-3

I have this input

<input type="text" [ngModel]="name" (ngModelChange)="name=$event">

And this.name = 'Adam';

When I get a new name from the back end and set the value with this.name = res.data, input value on page doesn't change. Why?

Ignat
  • 3,727
  • 6
  • 16
  • 17
  • 1
    Try with shorter version: [(ngModel)]="name" – Vlado Tesanovic Jan 21 '16 at 10:20
  • 1
    If the call to the server is done by code running outside Angular you need to use `constructor(private zone: NgZone){} ...zone.run(...)`. Your question doesn't provide enough information. Please explain how the value is changed. – Günter Zöchbauer Jan 21 '16 at 10:21
  • You need to give us more details on the way you get data from server. The problem is surely related to zone as Günter stated ;-) – Thierry Templier Jan 21 '16 at 10:23
  • This question with responses from Günter and I could help you: http://stackoverflow.com/questions/34875066/trouble-with-ngif-in-angular-2-typescript... – Thierry Templier Jan 21 '16 at 10:24

1 Answers1

0

Try this one.

<input type="text" [(ngModel)]="name">

If it is not working check your Class definition.

Abhilash Augustine
  • 4,128
  • 1
  • 24
  • 24