khalil _diouri
khalil _diouri

Reputation: 821

How to get ID of element ViewChild angular2 and jquery?

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

Answers (1)

norweny
norweny

Reputation: 313

  1. You have an extra parenthesis in your code.

    console.log( $(this.Item.nativeElement).attr('id')) );

  2. 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

Related Questions