Angular 1 中的链接函数 directive可以通过
定位 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);
}
}
关于angularjs - 如何将 `link` 函数替换为 Angular 2 组件中的目标 DOM 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36503017/