[英]How to replace `link` function to target DOM element in Angular 2 component
Link function in an Angular 1 directive makes it possible to target DOM elements, via Angular 1 指令中的链接功能可以通过以下方式定位DOM元素
link: function (scope, element, attr) {
// do something with element[0], e.g. put generated graphics
// inside the node
}
What's a replacement for that in Angular 2? 什么是Angular 2中的替代品?
This might do what you want: 这可能会做你想要的:
@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.