属性 'value' 在类型 'ElementRef' 上不存在

Property 'value' does not exist on type 'ElementRef'

我已经尝试设置 #name1 的值,如图所示 below.But 它显示编译时错误,如图所示 below.Can 请告诉我如何设置 [=] 的值16=] 组件?这里我使用的是单向数据绑定和模板驱动的方法。

[ts] Property 'value' does not exist on type 'ElementRef'.

.html

<ion-input type="text" name="{{question?.name}}" #name1="ngModel" ngModel> </ion-input>

.ts

  @ViewChild('name1') name1: ElementRef;

  constructor(){

   }

 getAnswer(){
     this.name1.value = 'Hello';//here it shows the above error
  }

使用组件类型而不是模板变量

@ViewChild(TextInput) name1: TextInput;

这也可能有效(我不知道 Ionic)。它可以与原生 HTML 输入元素一起使用,但如果它是 Angular 组件,则以上是首选方式。

this.name1.nativeElement.value = 'Hello';