gpt4 book ai didi

html - HTML 属性中的 AngularJS 条件

转载 作者:技术小花猫 更新时间:2023-10-29 12:10:00 27 4
gpt4 key购买 nike

如何根据模型更改 html 属性?

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

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

但这似乎行不通......

JS Bin code example .

最佳答案

三元运算符在这种情况下似乎不起作用,而不是这样做

{{cond ? true : false}}

改成

{{ exp && true || false }}

所以你的 placeholder 属性看起来像这样(为了演示目的我已经缩短了它)

placeholder="{{todos.length > 0 && 'Insert' || 'Insert first'}}"

关于html - HTML 属性中的 AngularJS 条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13780788/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com