您将如何根据模型更改html属性?
我正在根据数组的长度来更改输入的占位符文本:
<input placeholder="{{todos.length ? 'Insert todo' : 'Insert your first todo'}}" />
但这似乎不起作用
对于遇到这个问题的任何人(像我刚刚通过Google一样),似乎Angular最近对表达式中的三元运算符添加了支持.我在1.2.16中成功使用它来动态更新工具提示(title)属性.它似乎首先出现在1.2.17的文档中,尽管它们通常也不鼓励使用它:
原文链接:https://www.f2er.com/angularjs/143189.html来自:AngularJS: Developer Guide: Expressions
Apart from the ternary operator (a ? b : c),you cannot write a control flow statement in an expression. The reason behind this is core to the Angular philosophy that application logic should be in controllers,not the views. If you need a real conditional,loop,or to throw from a view expression,delegate to a JavaScript method instead.