What's the difference between ng-model and ng-bind

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 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-bind是从$scope -> view的单向绑定
ng-modle是$scope <-> view的双向绑定

在AngularJS中显示模型中的数据有两种方式:

<p>{{text}}</p>

另一种是使用基于属性的指令,叫做ng-bind:

<p ng-bind="text"></p>

主要区别在于,使用花括号语法时,在AngularJS使用数据替换模板中的花括号时,第一个加载的页面,通常是应用中的index.html,其未被渲染的模板可能会被用户看到。而使用第二站方法的视图不会遇到这种问题。

原因是,浏览器需要首先加载index.html页面,渲染它,然后AngularJS才能把它解析成你期望看到的内容。

所以,对于index.html页面中的数据绑定操作,建议采用ng-bind。那么在数据加载完成之前用户就不会看到任何内容。

AngularJS 关于ng-model和ng-bind还有{{}}的更多相关文章

  1. angular报错:angular.min.js:118Error: [ng:areq] http://errors.angularjs.org/1.5.8/ng/areq

    报错代码如下: <div ng-controller="HelloAngular"> <p>{{greeting.text}},angular</p& ...

  2. Part 14 ng hide and ng show in AngularJS

    ng-hide and ng-show directives are used to control the visibility of the HTML elements. Let us under ...

  3. angular.min.js:118 Error: [ng:areq] http://errors.angularjs.org/1.5.8/ng/areq?

    1,错误如图所示 简单说下错误原因是:没有js没有注册进去. 解决方法: 1.看下index.html有没有引入你的js文件. 2.看下app.js有没有注册js,比如我这次就是这步没做好,合并代码时 ...

  4. AngularJS中angular.min.js:80 Error: [ng:areq] http://errors.angularjs.org/1.2.9/ng/areq

    报出来的时候,出现这种错误,是因为在引入控制器的时候没有引入成功,我遇到这个错误是在因为没有将父控制器引入到子控制器中.

  5. AngularJS中实现Model缓存

    在AngularJS中如何实现一个Model的缓存呢? 可以通过在Provider中返回一个构造函数,并在构造函数中设计一个缓存字段,在本篇末尾将引出这种做法. 一般来说,Model要赋值给Scope ...

  6. Angular6之ng build | ng build --aot | ng build --prod 差异

    由于写了大半年的项目终于要告一段落并且即将进行第二阶段优化开发,emmm 基础版本已经二十多个模块了,必不可少的优化是很重要的,尽管项目上使用多层嵌套懒加载,但是在首屏加载的时候,任然很慢啊,因为一直 ...

  7. 在库中使用schematics——ng add与ng update

    起步 创建一个angular库 ng new demo --create-application=false ng g library my-lib 可见如下目录结构 ├── node_modules ...

  8. angularjs 1.3 综合学习 (one way bind , ng-if , ng-switch , ng-messages, ng-form ,ng-model )

    主要讲解1.3后的一些新功能,和一些以前没有介绍的小功能 (ng-if,ng-switch). 1.one way bind 这个之前的版本已经有人自己实现了,但是在1.3之后,angularjs 有 ...

  9. Error: [ng:areq]

    错误描述:Error: [ng:areq] http://errors.angularjs.org/1.4.8/ng/areq?p0=HelloCtrl&p1=not%20a%20functi ...

  10. 翻译-让ng的$http服务与jQuerr.ajax()一样易用

    Make AngularJS $http service behave like jQuery.ajax() 让ng的$http服务与jQuerr.ajax()一样易用 作者zeke There is ...

随机推荐

  1. LINUX | 谷歌云开启SSH及设置root密码

    一.设置root密码 1.先选择从浏览器打开ssh连接服务器 2.切换到root账号 sudo -i 3.设置root密码 passwd 然后会要求输入新密码,然后再重复一次密码,输入密码的时候不会显 ...

  2. Jmeter之集合点(Synchronizing timer 同步定时器)

    1.集合点介绍 LR中集合点可以设置多个虚拟用户等待到一个点,同时触发一个事务,以达到模拟真实环境下多个用户同时操作,实现性能测试的最终目的.jmeter中使用Synchronizing Timer实 ...

  3. docker容器composer 部署 laravel框架

    首先yum install docker     安装docker service docker start   启动docker docker pull  docker.io/skiychan/ng ...

  4. java 调用存储过程

    1.java 中调用pl/sql 中的存储过程 call 存储过程的名称(参数名称,参数名称)  在service 层中调用  存储过程  String  sql=" call  proc_ ...

  5. ieee文献免费下载办法

    sci-hub是个神奇的存在,但突然有短时间不能用了,搜索很久,找到了:https://www.zhihu.com/question/68333471/answer/276287163 这个网址会实时 ...

  6. 爬取qq号

    import reimport urllib.requestimport osimport jsonimport sslfrom collections import deque #把爬去的数据保存到 ...

  7. 分析easyswoole3.0源码,Trace组件(四)

    前文,我们访问地址的时候服务端会输出类似trace信息.那么原理是什么呢?其实es3已经把这个独立出来作为单独组件了,名字叫做Trace组件 在demo里的调用原理是 EasySwooleEvent: ...

  8. optional install error: Package require os(darwin) not compatible with your platform(win32)

    解决方法: cnpm rebuild node-sass cnpm install

  9. python3 第二十六章 - 内置函数之Number相关

    数学函数 函数 返回值 ( 描述 ) 实例 abs(x) 返回数字的绝对值,如abs(-10) 返回 10 print(abs(-10)) =======输出:====== 10 ceil(x) 返回 ...

  10. LinkedList - 好一个双向链表

    LinkedList是常用的集合结构之一,数据存储结构为链式存储,每个节点都有元素.前指针和后指针,指针指向了前节点和后节点的位置.同是LinkedList也是一个队列,实现了Deque接口,Dequ ...