【发布时间】:2018-06-05 00:06:49
【问题描述】:
我使用 ViewChild 的方式如下:
@Component({
selector: 'demo',
template: `<input type="text" #firstnameCtrl [(ngModel)]="firstname" />`
})
export class DemoComponent {
public firstname: string;
@ViewChild('firstnameCtrl') firstElementCtrl: ElementRef;
}
如果有人在模板中将导出的变量 #firstnameCtrl 更改为 #firstnameElement,则应用程序已损坏,但未引发编译器(也未在 AOT 中)。
那么有没有一种首选的方法来以更节省的方式绑定 ViewChild?
谢谢!
【问题讨论】: