Tonyukuk
Tonyukuk

Reputation: 6195

unable to see inital value at angularjs2 inputText

I am not able to see the initial value at inputText . I dont know what I am doing wrong but value should show the initial value as I know before.

Regards Alper

<input type="text" value="1" [(ngModel)]="Input.VSAT_input1" name="input1">

Upvotes: 1

Views: 33

Answers (2)

G&#252;nter Z&#246;chbauer
G&#252;nter Z&#246;chbauer

Reputation: 657228

ngModel doesn't work together with value. You need to assign the initial value to Input.VSAT_input1.

The [ngModel]="Input.VSAT_input1" part of your [(ngModel)]="Input.VSAT_input1" assigns the value of Input.VSAT_input1 to the <input>s value.

this.Input = initializeFromSomewhere();
this.Input.VSAT_input1 = 1; 

An alternative approach to avoid overriding the value of your model with an initial value:

[(ngModel)]="InputVSAT_input1" (ngModelChange)="Input.VSAT_input1 = $event";
InputVSAT_input1 = 1; 

ngOnInit() // or whatever you use to initialize your component
  this.Input = initializeFromSomewhere();
}

Upvotes: 3

Yoav Schniederman
Yoav Schniederman

Reputation: 5391

 Input.VSAT_input1 = 1;

<input type="text" [(ngModel)]="Input.VSAT_input1" name="input1">

Upvotes: 1

Related Questions