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进行改写整个样式,这时学习项目也变得好看多了,现在我们又需要目录再进行一次改变,如下图: 这样就符合之前讲的对学习目录进行布置了 ...
随机推荐
- Windows App开发之经常使用控件与应用栏
控件的属性.事件与样式资源 怎样加入控件 加入控件的方式有多种,大家更喜欢以下哪一种呢? 1)使用诸如Blend for Visual Studio或Microsoft Visual Studio X ...
- PDO:: 数据访问抽象层 ? :
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 【BZOJ4653】[Noi2016]区间 双指针法+线段树
[BZOJ4653][Noi2016]区间 Description 在数轴上有 n个闭区间 [l1,r1],[l2,r2],...,[ln,rn].现在要从中选出 m 个区间,使得这 m个区间共同包含 ...
- 【题解】T54037 最开始
传送门 题目大意: 对于\(a+ \frac 1{a^{}}=n\)求$a^{m}+ \frac 1{a^{m}} $,对\(10^9+7\)取模. 题目做法: 乍看此题,没有思路,但是如果用数学办法 ...
- 查找SAP 系统Parameter ID 4种方法
转自 http://blog.csdn.net/jy00873757/article/details/8517426 ***程序RPR_ABAP_SOURCE_SCAN 一.用F1,直接可以看到这个 ...
- 【shell】获取第10+个位置参数
转载自:http://www.cnblogs.com/sheldonxu/archive/2012/06/25/2560770.html 在Shell脚本中,可以用$n的方式获取第n个参数,例如,一个 ...
- keras: 在构建LSTM模型时,使用变长序列的方法
众所周知,LSTM的一大优势就是其能够处理变长序列.而在使用keras搭建模型时,如果直接使用LSTM层作为网络输入的第一层,需要指定输入的大小.如果需要使用变长序列,那么,只需要在LSTM层前加一个 ...
- gradle 与 gradlew
配置好gradle环境变量后(配置环境变量这里就不说了,可以自行百度),我们就可以在cmd中使用gradle命令了 在cmd中输入: gradle -v 输出如下: 这时说明gradle的环境变量配置 ...
- vue应用示例
1 . 实现轮播图 <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset=&q ...
- 让我们再谈谈 iOS 安全
前言 安全方面的话题总是聊不完的.这不,国外一家有名的专门攻击别人的安全公司 Hacking Team 自己被 Hack 了,结果有 400 多 G 的攻击资料泄漏出来,包括一些 0-day 的漏洞. ...