-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path03.scope.html
41 lines (35 loc) · 1017 Bytes
/
03.scope.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
<!DOCTYPE html>
<html>
<head>
<title>Angular Scope</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<script type="text/javascript">
// way 1 of doing this
/* var sample = angular.module("sample", []);
sample.controller("emp", function($scope){
$scope.name = "Rupa";
});*/
// way 2 of doing this, this is best practise, adding scope like this is called dependency injection
var sample = angular.module("sample", []);
sample.controller("emp", ["$scope", function(c){
c.name = "Rupa";
c.sal = 4500;
c.getAnnualSal = function(){
return (this.sal) * 12;
}
}]);
sample.controller("empinfo", ["$scope", function($scope){
$scope.name = "Tester";
$scope.city = "kolkata";
}]);
</script>
</head>
<body ng-app="sample">
<div ng-controller="emp">
Hello {{name}}! your sal is {{sal}}. Your annual salary is {{getAnnualSal()}}
</div>
<div ng-controller="empinfo">
Hello {{name}}! your current city is {{city}}.
</div>
</body>
</html>