[英]How to replace `link` function to target DOM element in Angular 2 component
Angular 1 指令中的鏈接功能可以通過以下方式定位DOM元素
link: function (scope, element, attr) {
// do something with element[0], e.g. put generated graphics
// inside the node
}
什么是Angular 2中的替代品?
這可能會做你想要的:
@Component({
...,
template: `
<div #target></div>
`
})
class MyComponent {
@ViewChild('target') target;
// lifecycle callback when `this.target` becomes available
ngAfterViewInit() {
var graph2d = new vis.Graph2d(
this.target.nativeElement, dataset, options);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.