Clicking a checkbox with ng-click does not update the model

前端 未结 10 1657
太阳男子
太阳男子 2020-12-04 13:17

Clicking on a checkbox and calling ng-click: the model is not updated before ng-click kicks in so the checkbox value is wrongly presented in the UI:

This works in An

10条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-04 13:40

    Usually this is due to another directive in-between your ng-controller and your input that is creating a new scope. When the select writes out it value, it will write it up to the most recent scope, so it would write it to this scope rather than the parent that is further away.

    The best practice is to never bind directly to a variable on the scope in an ng-model, this is also known as always including a "dot" in your ngmodel. For a better explanation of this, check out this video from John:

    http://www.youtube.com/watch?v=DTx23w4z6Kc

    Solution from: https://groups.google.com/forum/#!topic/angular/7Nd_me5YrHU

提交回复
热议问题