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进行改写整个样式,这时学习项目也变得好看多了,现在我们又需要目录再进行一次改变,如下图: 这样就符合之前讲的对学习目录进行布置了 ...
随机推荐
- MySQL 忘记密码解决办法
第一步: 关闭MySQL服务. 第二步: 打开DOS窗口,在里面输入安装MqSQL的目录本机为:C:\Program Files\MySQL\MySQL Server 5.6\bin 第三步: 在命 ...
- 【BZOJ1499】[NOI2005]瑰丽华尔兹 单调队列+DP
[BZOJ1499][NOI2005]瑰丽华尔兹 Description 你跳过华尔兹吗?当音乐响起,当你随着旋律滑动舞步,是不是有一种漫步仙境的惬意?众所周知,跳华尔兹时,最重要的是有好的音乐.但是 ...
- EasyPlayer RTSP Windows播放器D3D,GDI的几种渲染方式的选择区别
EasyPlayer-RTSP windows播放器支持D3D和GDI两种渲染方式,其中D3D支持格式如下: DISPLAY_FORMAT_YV12 DISPLAY_FORMAT_YUY2 DISPL ...
- jQuery 插件开发(1)
JavaScript 是一门混乱的语言,好的特性和坏的特性混杂在一起.而不同浏览器对标准的解析不一致,使得这门语言更加混乱,在这种情况下遵循最佳实践有诸多好处,至少不会掉入坑里.所以就有了<Ja ...
- Elipse clean后无法编译出class文件
通常之前一直运行正常的项目,在某次修改或重新启动时总是报 ClassNotFoundException,而事实是这个类确实存在,出现这种原因最好看看 build文件下的classes是否为空 或 编译 ...
- runsv
runsv(8) manual page http://smarden.org/runit/runsv.8.html Name runsv - starts and monitors a servic ...
- wepy/packages/wepy-web/src/helper/device.js
wepy/packages/wepy-web/src/helper/device.js https://github.com/Tencent/wepy/blob/bd0003dca2bfb958113 ...
- 我的Java开发学习之旅------>计算从1到N中1的出现次数的效率优化问题
有一个整数n,写一个函数f(n),返回0到n之间出现的"1"的个数.比如f(1)=1:f(13)=6,问一个最大的能满足f(n)=n中的n是什么? 例如:f(13)=6, 因为1, ...
- 流畅python学习笔记第十八章:使用asyncio编写服务器
在这一章中,将使用asyncio写一个TCP服务器.这个服务器的作用是通过规范名称查找Unicode字符,来看下代码: import asyncio from charfinder import Un ...
- 支付宝异步通知notify_url接收不了问题解决(转)
此处return_url可以成功跳转回网站页面但notify_url却接收不到支付宝的异步通知.已保证notify_url是一个外网可以访问的网址 1.网站用的是ssh框架,当支付宝发通知到我这个ac ...