if you want to set value than you can do the same in some function on click or on some event fire.(如果要设置值,则可以在单击或某些事件触发时在某些功能中执行相同的操作。)
also you can get value using ViewChild
using local variable like this(你也可以像这样使用局部变量使用ViewChild
获得价值)
<input type='text' id='loginInput' #abc/>
and get value like this(并得到这样的价值)
this.abc.nativeElement.value
here is working example(这是工作示例)
Update(更新资料)
okay got it , you have to use ngAfterViewInit
method of angualr2 for the same like this(好的,您必须像这样使用ngAfterViewInit
方法)
ngAfterViewInit(){
document.getElementById('loginInput').value = '123344565';
}
ngAfterViewInit
will not throw any error because it will render after template loading(ngAfterViewInit
将不会引发任何错误,因为它将在模板加载后呈现)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…