Checkbox not binding to scope in angularjs

前端 未结 4 958
旧时难觅i
旧时难觅i 2020-12-01 01:34

I am trying to bind a checkbox to scope using ng-model. The checkbox\'s initial state corresponds to the scope model just fine, but when I check/uncheck the checkbox, the m

4条回答
  •  不知归路
    2020-12-01 02:21

    Expanding on Matt's answer, please see this Egghead.io video that addresses this very issue and provides an explanation for: Why binding properties directly to $scope can cause issues

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

    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.

提交回复
热议问题