ngModel with a bind function not working in ng2

lqbweb picture lqbweb · Sep 13, 2016 · Viewed 9.8k times · Source

If I do in a template of a component something like:

<input [(ngModel)]="myProperty"></input>

then it works, but if I do it with a function in my component it does not:

<input [(ngModel)]="getMyProperty()"></input>

Here is the plunkr. Tested on RC6. Why?

Answer

Limitrof picture Limitrof · Jul 19, 2017

Try this construction

<input [ngModel]="getMyProperty()"></input>
  • use only square brackets.