【发布时间】:2016-09-30 10:16:43
【问题描述】:
如何将单选按钮的选中属性绑定到组件类的布尔变量?我想要的是,如果设置了布尔标志,则默认情况下会检查模板中的单选按钮。
我试过<input type="radio" [(ngModel)]="isSelected()">,但它会抛出模板语法错误
platform-browser.umd.js:962EXCEPTION: Error: Uncaught (in promise): Template parse errors:
Parser Error: Unexpected token '=' at column 13 in [isSelected()=$event] in ChoiceComponent@5:6 ("
(change)="select()"
required
[ERROR ->][(ngModel)]="isSelected()"> {{choice.text}}</label>
</div>
"): ChoiceComponent@5:6
【问题讨论】:
-
[(ngModel)]="isSelected()"无效。您不能双向绑定到函数。你的代码的意图是什么?isSelected()长什么样子?
标签: javascript html css typescript angular