[英]How to get ID of element ViewChild angular2 and jquery?
我需要在jquery和angular2的ViewChild之間建立關系
我嘗試了這個但是我得到了不確定的價值
@ViewChild('item', {read: ViewContainerRef}) Item;
console.log( $(this.Item.nativeElement).attr('id')) );
更新零件
<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');
}
您的代碼中有一個額外的括號。
console.log($(this.Item.nativeElement).attr('id') ) );
您確定HTML標記中具有“ id”屬性嗎? 如果您沒有,請添加它並嘗試下面的代碼:console.log($(this.Item.nativeElement).attr('id'));
答案已更新:
<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');
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.