-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path24.Lesson_$rootScope.html
76 lines (45 loc) · 1.93 KB
/
24.Lesson_$rootScope.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<!DOCTYPE html>
<html lang="tr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>24.Lesson_$rootScope</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.10/angular.min.js"></script>
<!-- rootScope, Factory Controller -->
<script>
var ControllerExample = angular.module("myapp", []);
ControllerExample.controller("mycontrol", function ($scope, $rootScope) {
//Tüm kontrol alanlarından ulaşılmak isteniyorsa rootscope kullanılmalıdır
$rootScope.text1 = "mycontrol tarafından yönetilen alan";
});
ControllerExample.controller("mycontrol2", function ($scope, $rootScope) {
//mycontrol alanında tanımlanan $rootScope.text1 değişkeni değerini mycontrol2 alanında tanımlanan $scope.text2 değişkenine atandı
$scope.text2 = $rootScope.text1;
});
/**
Şeklinde bir kullanımıda vardır. Bu şekilde ilk değer ataması gerçekleştirilebilir.
angular.module("myapp", [])
.run(function( $rootScope ){
$rootScope.test = "test";
})
.controller("mycontrol", function( $scope ){
})
.controller("mycontrol2", function( $scope ){
});
***NOT: mycontrol ve mycontrol2 scopuna bakan angular bu controllerın scope alanında "test" alanını bulamadığı için $rootScope alanına bakacaktır.
*/
</script>
</head>
<!--
$scope ifadesi sadece bulunduğu controller'ın altında kullanılmaktadır.
$rootScope ile aynı değişkenleri farklı controllerlarda kullanılabilmektedir.
-->
<body ng-app="myapp">
<div ng-controller="mycontrol">
{{text1}}
</div>
<div ng-controller="mycontrol2">
{{text2}}
</div>
</body>
</html>