ngModel with a bind function not working in ng2

泄露秘密 提交于 2020-01-01 08:28:34

问题


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?


回答1:


Try this construction

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


来源:https://stackoverflow.com/questions/39468450/ngmodel-with-a-bind-function-not-working-in-ng2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!