Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have tried to set the value of #name1 as shown below.But it shows compile time error as shown below.Can you please tell me how to set the value for the text component? Here I'm using one-way data bind and template-driven approach.

[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
  }
like image 512
Sampath Avatar asked May 08 '17 09:05

Sampath


1 Answers

Use the components type instead of a template variable

@ViewChild(TextInput) name1: TextInput;

This might also work (I don't know Ionic). It would work with a native HTML input element, but above is the preferred way if it's an Angular component.

this.name1.nativeElement.value = 'Hello';
like image 158
Günter Zöchbauer Avatar answered Oct 23 '22 10:10

Günter Zöchbauer