首页 > 代码库 > Angular_(作用域层次结构)
Angular_(作用域层次结构)
html部分
.........................................................................................
<!doctype html>
<html ng-app="myApp">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<div ng-controller="LevelA">
<h3>{{title}}</h3>
ValueA = {{valueA}} <input type="button" ng-click="inc()" value="http://www.mamicode.com/+" />
<div ng-controller="LevelB"><hr>
<h3>{{title}}</h3>
ValueA = {{valueA}}<br>
ValueB = {{valueB}}
<input type="button" ng-click="inc()" value="http://www.mamicode.com/+" />
<div ng-controller="LevelC"><hr>
<h3>{{title}}</h3>
ValueA = {{valueA}}<br>
ValueB = {{valueB}}<br>
ValueC = {{valueC}}
<input type="button" ng-click="inc()" value="http://www.mamicode.com/+" />
</div>
</div>
</div>
<script src="http://www.mamicode.com/js/angular-1.3.0.js"></script>
<script src="http://www.mamicode.com/js/作业3_作用域继承.js"></script>
</body>
</html>
...........................................................................
js部分
myApp=angular.module("myApp",[]);
myApp.controller("LevelA",function ($scope,$rootScope) {
$scope.valueA=0; //初始化
$scope.valueB=0; //初始化
$scope.valueC=0; //初始化
$scope.title="LevelA";
$scope.inc=function () {
$scope.valueA++;
$rootScope.valueB++;
$rootScope.valueC++;
}
})
myApp.controller("LevelB",function ($scope,$rootScope) {
$scope.title="LevelB";
$scope.inc=function () {
$scope.valueB++;
$rootScope.valueC++;
}
})
myApp.controller("LevelC",function ($scope) {
$scope.title="LevelC";
$scope.inc=function () {
$scope.valueC++;
}
})
Angular_(作用域层次结构)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。