Angular $scope和$rootScope
<!DOCTYPE html>
<html ng-app='myModule'>
<head lang="en">
<meta charset="UTF-8">
<script src="js/angular.js"></script>
<title></title>
</head>
<body>
<div ng-controller="myCtrl01">
<p>{{"num1 in myCtr01 is "+num1}}</p>
<p>{{"num2 in myCtr01 is "+num2}}</p>
</div>
<div ng-controller="myCtrl02">
<p>{{"num1 in myCtr02 is "+num1}}</p>
<p>{{"num2 in myCtr02 is "+num2}}</p>
<!-- myCtrl03的$scope
就是myCtrl02$scope的子组用对象-->
<div ng-controller="myCtrl03">
<p>{{"num3 in myCtrl03 is "+num3}}</p>
</div>
</div>
<script>
var app = angular.module('myModule', ['ng']);
app.controller('myCtrl01',
function ($scope, $rootScope) {
console.log('myCtrl01 func is called');
$scope.num1 = 10;
console.log($scope);
console.log($rootScope);
$rootScope.num2 = 100;
})
app.controller('myCtrl02', function ($scope) {
console.log('myCtrl02 func is called');
console.log($scope);
$scope.num3 = 99;
})
app.controller('myCtrl03', function ($scope) {
})
</script> </body>
</html>
Angular $scope和$rootScope的更多相关文章
- Angular $scope和$rootScope事件机制之$emit、$broadcast和$on
Angular按照发布/订阅模式设计了其事件系统,使用时需要“发布”事件,并在适当的位置“订阅”或“退订”事件,就像邮箱里面大量的订阅邮件一样,当我们不需要时就可以将其退订了.具体到开发中,对应着$s ...
- AngularJS进阶(二十一)Angularjs中scope与rootscope区别及联系
Angularjs中scope与rootscope区别及联系 scope是html和单个controller之间的桥梁,数据绑定就靠他了.rootscope是各个controller中scope的桥梁 ...
- ng $scope与$rootScope的关系
$scope与$rootScope的关系:①不同的控制器之间 是无法直接共享数据②$scope是$rootScope的子作用域对象$scope的id是随着控制器的加载顺序依次递增,$rootScope ...
- Part 37 Difference between $scope and $rootScope
In this video we will discuss the difference between $scope and $rootScope. The main difference is t ...
- angular源码分析:angular中$rootscope的实现——scope的一生
在angular中,$scope是一个关键的服务,可以被注入到controller中,注入其他服务却只能是$rootscope.scope是一个概念,是一个类,而$rootscope和被注入到cont ...
- (九)通过几段代码,理清angularJS中的$injector、$rootScope和$scope的概念和关联关系
$injector.$rootScope和$scope是angularJS框架中比較重要的东西,理清它们之间的关系,对我们兴许学习和理解angularJS框架都很实用. 1.$injector事实上是 ...
- AngularJS的$rootScope和$scope联系和区别
scope是html和单个controller之间的桥梁,数据绑定就靠他了. rootscope是各个controller中scope的桥梁.用rootscope定义的值,可以在各个controlle ...
- Angular作用域的层级概念(scope)
首先引入 angular 的根作用域:$rootScope ng-app:定义了angualr的作用域 ng-controller:定义了控制器 $scope定义了视图与控制器之间的纽带,而scope ...
- AngularJS 深入理解 $scope
$scope 的使用贯穿整个 AngularJS App 应用,它与数据模型相关联,同时也是表达式执行的上下文.有了$scope 就在视图和控制器之间建立了一个通道,基于作用域视图在修改数据时会立刻更 ...
随机推荐
- go标准库的学习-net/http
参考:https://studygolang.com/pkgdoc 概念解释: request:用户请求的信息,用来解析用户的请求信息,包括post.get.cookie.url等信息 respons ...
- ethereum/EIPs-712 Ethereum typed structured data hashing and signing
https://github.com/ethereum/EIPs/blob/master/EIPS/eip-712.md eip title author discussions-to status ...
- adb报错问题解决方法
1,报错信息:adb server version (31) doesn't match this client (40); killing 解决方法: 一: 主要是前面的31或者其他,比如32/31 ...
- 单例模式和JDBC
配置文件: driver=com.mysql.jdbc.Driver url=jdbc:mysql://localhost:3306/blog user=root user=1234 properti ...
- web测试工具列表
ab.webbench,siege,loadrunner(专业的测试软件可形成图表.) 推荐使用ab测试. tcp并发测试: c1000k
- 【Topcoder 10107】TeamManagement
Topcoder 10107 题意:给定一棵树,其中有些点是忠诚的,现在要选k个点,每个选择的联通块都必须包含一个忠诚的点,求包含某个点的概率. 思路:考虑树型\(dp\),\(dp(i,j,0/1, ...
- 洛谷 P1525 关押罪犯
题目链接 https://www.luogu.org/problemnew/show/P1525 题目描述 S城现有两座监狱,一共关押着N名罪犯,编号分别为1−N.他们之间的关系自然也极不和谐.很多罪 ...
- TCP/IP协议--TCP的交互数据流和成块数据流
前边讲了TCP连接的建立和终止,分别要三次握手和四次通信.这些报文段都只包含首部,没有数据部分. 这里就讲讲数据传送的一些细节.一个TCP连接建立成功以后,就可以开始传送数据了~ 一般TCP数据 ...
- 学习angularjs的ng-hide和ng-disabled
一,页面上有一个checkbox和一个文本框.切换checkbox能对文本框输入文本与否: <input type="checkbox" ng-model="ckS ...
- 计算几何总结(Part 1~2)
Preface 对于一个初三连三角函数都不会的蒟蒻来说计算几何简直就是噩梦. 反正都是要学的也TM没办法,那就慢慢一点点学起吧. 计算几何要有正确的板子,不然那种几百行CODE的题写死你. 本蒟蒻的学 ...