ng-model 和 ng-bind 有什么区别
我目前正在学习 AngularJS,但很难理解 ng-bind
和 ng-model
之间的区别.
I'm currently learning AngularJS and am having difficulty understanding the difference between ng-bind
and ng-model
.
谁能告诉我它们有什么不同,什么时候应该使用一个?
Can anyone tell me how they differ and when one should be used over the other?
ng-bind 具有单向数据绑定($scope --> 视图).它有一个快捷方式 {{ val }}
它显示了插入到 html 中的范围值 $scope.val
,其中 val
是一个变量名.
ng-bind has one-way data binding ($scope --> view). It has a shortcut {{ val }}
which displays the scope value $scope.val
inserted into html where val
is a variable name.
ng-model 旨在放置在表单元素内部并具有双向数据绑定($scope --> 视图和视图 --> $scope)例如.
ng-model is intended to be put inside of form elements and has two-way data binding ($scope --> view and view --> $scope) e.g. <input ng-model="val"/>
.