Angular $scope和$rootScope
Angular Scope
2023-09-11 14:17:23 时间
<!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 - First Demo
- [Angular] Communicate Between Components Using Angular Dependency Injection
- [Angular] Write Compound Components with Angular’s ContentChild
- [Angular 2] BYPASSING PROVIDERS IN ANGULAR 2
- [Angular 2] @ViewChild to access Child component's method
- [Angular 2] Refactoring mutations to enforce immutable data in Angular 2
- [AngularJS] New in Angular 1.5 ng-animate-swap
- [Angular 2] Template property syntax
- [AngularJS] Using the Angular scope $destroy event and method
- [Angular] Isolate Scope "@"
- [Angular RxJS] Single data observable pattern (combineLatest with startWith)
- [Angular] Angular i18n Pluralization Support
- [Angular] Auxiliary named router outlets
- [Angular 2] ROUTING IN ANGULAR 2 REVISITED
- [AngularJS] angular-md-table for Angular material design
- [Angular 2] Using a Value from the Store in a Reducer
- [Angular 2] Using ng-for to repeat template elements
- [AngularJS] Using the Angular scope $destroy event and method
- [Angular]Isolate scope "=", two ways bindings
- [Angular] Parent scope, scope overwritten, using factory() to share data between controller
- angular controller as syntax vs scope
- Angular HTTPClient API 在 SAP 电商云中的使用
- Angular数据绑定的学习笔记