AngularJs(Part 1)
I am tired to translate these into Chinese.
but who cares? i write these posts just for myself
Scope
a new scope is created by the ng-controller directive using
the Scope.$new() method call.
yes , we need to have at least one instance of a scope before
creating a new scope!
so here is the $rootScope. it is the paremt of all the other
scopes. the $rootScope instance gets created when a new
application is bootstrapped.
each scope contains a property $parent which points to its parent scope.
ng-controller is a scope-created directive.
there are many other scope-created directives.
Scopes form a parent-child ,tree-like relationship rooted at
the $rootScope instance. and scopes' creation is driven by the DOM tree.
check the famous ng-repeat.
let's say a HTML snippet<li ng-repeat='per in persons'>{{per.name}}</li>
when interating persons, a new variable needs to be created to hold each per.
it seems the Google does not use the strategy that just simplely override previous value.
instead , it creats a new scope for each per and expose the scope to maybe the parent scope $scope.
in this way, it's possible to create variable with the same name on different scopes without createing name collisions.
in above snippet, every <li> element gets its own scope when the per variable can be defined.
as i say above ,each $scope except the $rootScope contains a property $parent which pointing to parent scope,
so all properties defined in parent scope is actually available to child scope.
Scope's inheritance in AngularJs follws the same rules as prototypical inheritance in JavaScript.(when we try to read
as property, the inheritance tree will be traversed upwards till a property is found.)
Scopes are responsible to creat variables.
they are to provide isolated namespaces and avoid name collisions.
they can be destroyed and the garbage collection will deallocate the resource.
AngularJs(Part 1)的更多相关文章
- angularJS(6)
angularJS(6) 一:angularJs的事件. 1.ng-click指令定义了AngularJS点击事件. <div ng-app="myapp" ng-contr ...
- angularJS(5)
angularJS(5) 一,数据循环:特别要注意作用域 使用ng-repeat指令. <div ng-app="myApp" ng-controller="myC ...
- angularJS(4)
angularJS(4) 一:angulaJs的作用域scope Scope(作用域) 是应用在 HTML (视图) 和 JavaScript (控制器)之间的纽带.scope 是一个 JavaScr ...
- angularJS(3)
angularJS(3) 一.angularJs的指令模型ng-model指令 ng-model 指令 绑定 HTML 元素 到应用程序数据. 为应用程序数据提供类型验证(number.email ...
- angularJS(2)
angularJS(2) 今天先讲一个angularJs的表单绑定实例: <div ng-app="myApp" ng-controller="formCtrl&q ...
- AngularJS(1)
AngularJS(1) 在讲正题之前,先说一下有关angular简介方面的信息: 1. angularJS 诞生于2009年,由Misko Hevery 等人创建,后为Google所收购.是一款优 ...
- 学习笔记-AngularJs(十)
前面一直在说自定义指令,但是却一直没有一次系统地去了解,现在需要我们一起来学习如何去使用自定义指令,去丰富html标签.属性,实现多元化.多功能的标签(或是属性).辣么,啥是指令?要了解指令,首先需要 ...
- 学习笔记-AngularJs(九)
到目前为止,我们所做的学习案例都是没有加任何动画效果的,对于以往来说,我们经常会去使用一些动画插件或是css框架(如:animate.css)来点缀我们的网页,这样显得生动,高大上,那么接下来我们可以 ...
- 学习笔记-AngularJs(七)
在学习笔记-AngularJs(六)提及了事件处理器和过滤器以及它们的例子,而我们知道之前我是使用$http服务去获得我们需要的json数据,但是$http是比较底层的用法,有时候我们想把获取json ...
- 学习笔记-AngularJs(六)
在学习笔记-AngularJs(五),通过引入bootstrap.css进行改写整个样式,这时学习项目也变得好看多了,现在我们又需要目录再进行一次改变,如下图: 这样就符合之前讲的对学习目录进行布置了 ...
随机推荐
- JS基础常识理解
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- java常用的基础容器
1 Vector and ArrayList 它们都是可以随机访问的.它们的区别是Vector是线程安全的,而ArrayList不是线程安全的. 2 HashMap的底层实现机制 2.1 底层数据结构 ...
- json (js对象标记)
基础 JSON: JavaScript Object Notation (JavaScript对象表示法) 网络媒体类型是 application/json,文件名扩展是 .json JSON 独立于 ...
- centos 7 官网安装 PostgreSQL
https://www.postgresql.org/download/linux/redhat/
- Cordova插件相关常用命令
一,插件相关常用命令 1,查看所有已经安装的插件 1 cordova plugin ls 2,安装插件(以camera插件为例) 1 cordova plugin add cordova-plug ...
- Machine Learning in Action(4) Logistic Regression
从这节算是开始进入“正规”的机器学习了吧,之所以“正规”因为它开始要建立价值函数(cost function),接着优化价值函数求出权重,然后测试验证.这整套的流程是机器学习必经环节.今天要学习的话题 ...
- 5.2 《锋利的jQuery》jQuery对表格的操作(选项卡/换肤)
表格隔行变色以及单选/复选 表格展开关闭 表格筛选 字体变大/缩小 选项卡 网页换肤 tip1: $("tr:odd")和$("tr:even")选择器索引是从 ...
- 一.编译nginx
前往nginx.org下载需要的nginx版本,解压之后目录如下: auto : 主要存放辅助configure脚本执行时的文件, 例如判定nginx支持的模块,操作系统可供nginx使用的特性等. ...
- JAVA-配置path环境
配置path环境变量变的目的是什么? 控制台可以在任意的路径下都可以找到java的开发工具. 为了说明几个JDK环境变量的作用,这里先给出环境变量的定义 环境变量: 环境变量一般是指在操作系统中用来指 ...
- python读写txt大文件
直接上代码: import easygui import os path = easygui.fileopenbox()#path是打开的文件的全路径 if path:#如果选择打开文件,没有选择取消 ...