加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

AngularJS条件在HTML属性

发布时间:2020-12-17 07:48:40 所属栏目:安全 来源:网络整理
导读:您将如何根据模型更改html属性? 我正在根据数组的长度来更改输入的占位符文本: input placeholder="{{todos.length ? 'Insert todo' : 'Insert your first todo'}}" / 但这似乎不起作用 JS Bin code example. 对于遇到这个问题的任何人(像我刚刚通过Google
您将如何根据模型更改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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读