AngularJS conditionals in HTML Attribute

后端 未结 2 752
伪装坚强ぢ
伪装坚强ぢ 2021-02-12 16:22

How would you change an html attribute based on the model?

I\'m trying to change an input\'s placeholder text based on a length of an array:



        
2条回答
  •  伪装坚强ぢ
    2021-02-12 16:59

    The ternary operator doesn't seem to work in this case, instead of doing this

    {{cond ? true : false}}
    

    Change it to

    {{ exp && true || false }}
    

    So your placeholder attribute would look like this (I have shortened it for demonstration purposes)

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

提交回复
热议问题