angular trigger changes with $watch vs ng-change, ng-checked, etc

后端 未结 4 897
遥遥无期
遥遥无期 2020-12-04 19:10

Currently we could monitor data changes with several ways. We could trigger model changes with $watch and we could add directives to elements and bind some acti

4条回答
  •  感动是毒
    2020-12-04 19:55

    If you want two-way data binding, then use ng-model. This pushes changes from model to view and from view to model -- two ways. However, if you just want one-way data binding from view to model, then use ng-change. If you want simple one way data binding from model to view, you can use an expression {{ like_this }}. But if you want a lot more control over how the model is rendered in the view, or if you want to bind the model to something other than the view, then use a $watch.

提交回复
热议问题