ng-model 和 ng-bind 有什么区别 [英] What's the difference between ng-model and ng-bind

查看:35
本文介绍了ng-model 和 ng-bind 有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在学习 AngularJS,但很难理解 ng-bindng-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"/>.

这篇关于ng-model 和 ng-bind 有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆