[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 ...
随机推荐
- ios实现类似魔兽小地图功能 在
写了一个类似魔兽小地图功能的控件. 比如你有一个可以放大缩小的scrollView.会在里面进行一些放大缩小,点击里面的按钮呀,等操作. 这个小地图控件.就会和你的大scrollView同步.并有缩略 ...
- [Everyday Mathematics]20150204
设 $k_0>0$, $\phi:[k_0,\infty)\to[0,\infty)$ 是有界递减函数, 并且 $$\bex \phi(k)\leq \frac{A}{(k-h)^\al}\ph ...
- 细雨学习笔记:Jmeter之post processors(后置处理器)
后置处理器
- 网站繁简切换的JS遇到的一个BUG
公司打算进入台湾市场,最近开发了繁体版本的网站,数据库里的信息全是简体,除了网页上固定的文字手动翻译了,文章内容标题都不是繁体. 于是在网上找了一段比较流行的繁简切换的JS实现了,不过后来却发现,有些 ...
- ASP.NET MVC3 系列教程 - Razor视图引擎基础语法
http://www.cnblogs.com/highend/archive/2011/04/09/aspnet_mvc3_razor_engine.html 4. 关于所有带"_" ...
- CDH版HDFS Block Balancer方法
命令: sudo -u hdfs hdfs balancer 默认会检查每个datanode的磁盘使用情况,对磁盘使用超过整个集群10%的datanode移动block到其他datanode达到均衡作 ...
- list、tuple、dict、set、map
list Python内置的一种数据类型是列表. list是一种有序的集合,可以随时添加和删除其中的元素. # 创建list classmate = ['micheal', 'Bob', 'Tracy ...
- [现代程序设计]homework-03
Homework-03 队员: 11061193 薛亚杰 11061192 周敏轩 11061190 李孟 材料阅读 我们三个人将以下材料仔细阅读,觉得十分受益.下面是我们的总结和分享: 1)代 ...
- Spring4整合Hibernate4详细示例
1. Spring整合Hibernate,主要是解决什么问题? a.让Spring提供的IOC容器来管理Hibernate的SessionFactory b.让Hibernate使用Spring提供的 ...
- iOS本地数据存取
应用沙盒 1)每个iOS应用都有自己的应用沙盒(应用沙盒就是文件系统目录),与其他文件系统隔离.应用必须待在自己的沙盒里,其他应用不能访问该沙盒 2)应用沙盒的文件系统目录,如下图所示(假设应用的名称 ...