它提供了对视图中元素或组件的引用:
@Component({
...
directives: [SomeComponent],
template: `
<div><span #myVar>xxx</span><div>
<some-comp></some-comp>`
})
class MyComponent {
@ViewChild('myVar') myVar:ElementRef;
@ViewChild(SomeComponent) someComponent:SomeComponent;
ngAfterViewInit() {
console.log(this.myVar.nativeElement.innerHTML);
console.log(this.someComponent);
}
}
变量未初始化 ngAfterViewInit()
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句