Setting ngTrueValue and ngFalseValue to numbers

前端 未结 4 573
轻奢々
轻奢々 2020-12-28 14:23

Update: question is obsolete for latest Angular version, see tsh\'s comment on this post


I have bound a checkbox to a value:

&         


        
4条回答
  •  执念已碎
    2020-12-28 14:43

    The first approach above is great. That's works fine. You can also use ng-change directive if you need use dynamic model (e.g. linked with ID or number - in case you wanna work with ID you don't know ahead). Just pass model as parameter: ng-change="fooBar(model[ID])" , catch in controller function and use Number(model[ID]) re-type. That's convert true as 1, false as 0 and you can work with this.

提交回复
热议问题