AngularJS条件在HTML属性

您将如何根据模型更改html属性

我正在根据数组的长度来更改输入的占位符文本:

<input placeholder="{{todos.length ? 'Insert todo' : 'Insert your first todo'}}" />

但这似乎不起作用

JS Bin code example.

对于遇到这个问题的任何人(像我刚刚通过Google一样),似乎Angular最近对表达式中的三元运算符添加支持.我在1.2.16中成功使用它来动态更新工具提示(title)属性.它似乎首先出现在1.2.17的文档中,尽管它们通常也不鼓励使用它:

来自: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.

相关文章

ANGULAR.JS:NG-SELECTANDNG-OPTIONSPS:其实看英文文档比看中...
AngularJS中使用Chart.js制折线图与饼图实例  Chart.js 是...
IE浏览器兼容性后续前言 继续尝试解决IE浏览器兼容性问题,...
Angular实现下拉菜单多选写这篇文章时,引用文章地址如下:h...
在AngularJS应用中集成科大讯飞语音输入功能前言 根据项目...
Angular数据更新不及时问题探讨前言 在修复控制角标正确变...