[AngularJS] Javascript scope and AngularJS $scope
Scope resolution of our Angular documents works exactly the same way scope resolution works in plain, old Javascript. The only difference here is that what actually matters about scope inheritance is the structure of our dom.
If the child controller doesn't have, will find in $rootScope.
<!DOCTYPE html>
<html ng-app="app">
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<h1>RootScope</h1>
{{posts | json}}
<div ng-controller="FirstController">
<h1>FirstController</h1>
{{posts | json}}
</div> <div ng-controller="SecondController">
<h1>SecondController</h1>
{{posts | json}}
</div>
<div ng-controller="FirstController">
<h1>Second as innercontroller (first contains second)</h1>
<div ng-controller="SecondController">
{{posts | json}}
</div>
</div> <div ng-controller="SecondController">
<h1>First as innercontroller (second contains first)</h1>
<div ng-controller="FirstController">
{{posts | json}}
</div>
</div> <div ng-controller="FirstController">
<div ng-controller="SecondController">
<h1>First & Second don't have</h1>
{{youdonthave}}
</div>
</div> <script src="bower_components/angular/angular.min.js"></script>
<script src="./app.js"></script>
</body>
</html>
/**
* Created by Answer1215 on 1/2/2015.
*/
angular.module('app', [])
.run(function($rootScope) {
$rootScope.posts = [7,8,9];
$rootScope.youdonthave = "All child don't have";
})
.controller('FirstController', function($scope) {
$scope.posts = [1,2,3];
})
.controller('SecondController', function($scope) {
$scope.posts = [4,5,6];
})

[AngularJS] Javascript scope and AngularJS $scope的更多相关文章
- JavaScript文件中调用AngularJS内部方法或改变$scope变量
		
需要在其他JavaScript文件中调用AngularJS内部方法或改变$scope变量,同时还要保持双向数据绑定: 首先获取AngularJS application: 方法一:通过controll ...
 - AngularJS 全局scope与Isolate scope通信
		
在项目开发时,全局scope 和 directive本地scope使用范围不够清晰,全局scope与directive本地scope通信掌握的不够透彻,这里对全局scope 和 directive本地 ...
 - 关于AngularJS学习整理---浅谈$scope(作用域)  新手必备!
		
作为初次接触 AngularJS的新手,想要深层理解里面的内容短时间还是不可能的,所以标题写了浅谈字样,以下内容是参考各位大神以及相关书籍整理加个人理解,出现错误的地方请大家指正. $scope(作用 ...
 - AngularJS 全局scope与指令 scope通信
		
在项目开发时,全局scope 和 directive本地scope使用范围不够清晰,全局scope与directive本地scope通信掌握的不够透彻,这里对全局scope 和 directive本地 ...
 - angularjs探秘<五> 举足轻重的scope
		
scope在angular中的作用可谓举足轻重,不理解scope就不会angular: scope是应用在 HTML (view) 和 JavaScript (controller)之间的纽带. sc ...
 - 精通AngularJS(三)深入scope,继承结构,事件系统和生命周期
		
深入探讨 Scope 作用域 每一个 $scope 都是类 Scope 的一个实例.类 Scope 拥有可以控制 scope 生命周期的方法,提供事件传播的能力,并支持模板渲染. 作用域的层次结构 让 ...
 - AngularJS中Directive指令系列 - scope属性的使用
		
文章是转的,我做下补充.原文地址:https://segmentfault.com/a/1190000002773689 每当一个指令被创建的时候,都会有这样一个选择,是继承自己的父作用域(一般是外部 ...
 - JavaScript的作用域(Scope)和上下文(Context)
		
JavaScript对于作用域(Scope)和上下文(Context)的实现是这门语言的一个非常独到的地方,部分归功于其独特的灵活性. 函数可以接收不同的的上下文和作用域.这些概念为JavaScrip ...
 - AngularJS自定义指令directive:scope属性 (转载)
		
原文地址:http://blog.csdn.net/VitaLemon__/article/details/52213103 一.介绍: 在AngularJS中,除了内置指令如ng-click等,我们 ...
 - AngularJS学习笔记之directive—scope选项与绑定策略
		
From:http://www.linuxidc.com/Linux/2015-05/116924.htm scope:{}使指令与外界隔离开来,使其模板(template)处于non-inherit ...
 
随机推荐
- poj 4052(ac自动机)
			
题意:自己百度吧!! 分析:就是通过它的fail指针来找出它的子串就行了,这题其实不难的.这好像还是金华邀请赛的题哦! 代码实现: #include<cstdio> #include< ...
 - [转]  C#实现自动化Log日志
			
qing2005原文地址 C#实现自动化Log日志 在开发项目的时候,我们不免要使用Log记录日志,使用最多的是Log4Net和EntLib Log,在需要记录日志的代码处加入log.Write(日志 ...
 - Conversion to Dalvik format failed: Unable to execute dex: null
			
[2013-11-19 14:18:48 - Dex Loader] Unable to execute dex: java.nio.BufferOverflowException. Check th ...
 - 使用SQL语句清空数据库所有表的数据
			
使用SQL语句清空数据库所有表的数据 近来发现数据库过大,空间不足,因此打算将数据库的数据进行全面的清理,但表非常多,一张一张的清空,实在麻烦,因此就想利用SQL语句一次清空所有数据.找到了三种方法进 ...
 - Linux 系统编程
			
简介和主要概念 Linux 系统编程最突出的特点是要求系统程序员对它们工作的的系统的硬件和操作系统有深入和全面的了解,当然它们还有库和系统调用上的区别. 系统编程分为:驱动编程.用户空间编程和网络编程 ...
 - [Tommas] 测试用例覆盖率(三)
			
三.测试数据的设计 每一个测试思路最终都要转化成具体的数据才能来执行.关于测试数据设计的方法也不外乎那几种,就不再赘述了.此处单就一些经常易犯的错误,提出一些注意点,作为用例数据设计时的参考: 1.尽 ...
 - 【和我一起学python吧】Python 启航
			
话说万张高楼平地起,不会走之前先学会爬吧.尤其对于我等的小菜同学来说更是这样,不管怎么先code first吧,等我等小菜们翅膀硬了才test first吧. 1, 怎么运行python? 先到pyt ...
 - Motan学习开篇
			
你已经走到这里了,后面只要耐心的走下去就行了. --佚名 入职新公司以后,公司使用dubbo框架,简单的照葫芦画瓢之后,也算是入手了,但是其中内部的实现的机制一概不懂.我单纯的有种好奇心,觉得每个 ...
 - 问题:关于一个坛友的html布局实现
			
来源:http://www.ido321.com/888.html 坛友的需求如图 这个跟上次贴友分类菜单的实现类似 html: 1: <body> 2: <div class=&q ...
 - 1.1……什么是3G
			
移动通信技术的发展 第一代移动通信技术(1st - Generation),只能进行语音通话. 第二代移动通信技术(2nd - Generation),可以收发短信.可以上网,但速度只有几十Kbps, ...