Reputation: 821
I need to have a relation between jquery and ViewChild of angular2
I tried this but I get undefined value
@ViewChild('item', {read: ViewContainerRef}) Item;
console.log( $(this.Item.nativeElement).attr('id')) );
update part
<div class="container col411 col-sm-4" id="div411Item"
style="border: 1px solid #9DA0A4;" (dblclick)="ActiveEditcol411()" #Item>
new content
</div>
ActiveEditcol411(){
$('#Item').prop('contenteditable','true');
}
Upvotes: 0
Views: 8881
Reputation: 313
You have an extra parenthesis in your code.
console.log( $(this.Item.nativeElement).attr('id')) );
Are you sure you have "id" attribute in your html tag? If you don't have one, add it and try the code below: console.log( $(this.Item.nativeElement).attr('id') );
Answer updated:
<div class="container col411 col-sm-4" id="div411Item" style="border: 1px solid #9DA0A4;" (dblclick)="ActiveEditcol411()" #Item>
new content
</div>
@ViewChild('Item', {read: ViewContainerRef}) Item;
ActiveEditcol411(){
$(this.Item.element.nativeElement).prop('contenteditable','true');
}
Upvotes: 4