带有绑定功能的 ngModel 在 ng2 中不起作用 [英] ngModel with a bind function not working in ng2

查看:33
本文介绍了带有绑定功能的 ngModel 在 ng2 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在组件的模板中执行以下操作:

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>

这里是 plunkr.在 RC6 上测试.为什么?

Here is the plunkr. Tested on RC6. Why?

推荐答案

试试这个结构

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

  • 仅使用方括号.
  • 这篇关于带有绑定功能的 ngModel 在 ng2 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆