-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path20.isolated-scope-in-directive.js
91 lines (81 loc) · 1.63 KB
/
20.isolated-scope-in-directive.js
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
var app = angular.module('app', []);
app.controller('parent', ['$scope', function($scope){
// for string
$scope.a = 10;
$scope.b = 11;
$scope.p = 12;
$scope.q = 13;
// for object
$scope.emp = {
empno : 1001,
name : "test"
}
$scope.emp2 = {
empno : 1002,
name : "test2"
}
// for function
$scope.x = 10;
$scope.y = 11;
$scope.doSum = function(x, y){
var r = parseInt(x) + parseInt(y);
alert('Sum ' + r);
}
}]);
// accessed string from directive
app.directive('message', function(){
return {
templateUrl : 'templates/tmpl-isolated-scope-str.html',
scope : {
x : '@',
y : '@'
},
controller : function($scope, $element, $attrs){
$scope.doProcess = function(){
var r = parseInt($scope.x) + parseInt($scope.y);
alert("Sum " + r);
}
}
}
});
app.directive('message2', function(){
return {
templateUrl : 'templates/tmpl-isolated-scope-str.html',
scope : {
x : '@m',
y : '@n'
}
}
});
// accessed object from directive
app.directive('messageObj', function(){
return {
templateUrl : 'templates/tmpl-isolated-scope-obj.html',
scope : {
employee : '='
}
}
});
app.directive('messageObj2', function(){
return {
templateUrl : 'templates/tmpl-isolated-scope-obj.html',
scope : {
employee : '=oEmp'
}
}
});
// accessed function from directive
app.directive('messageFun', function(){
return {
templateUrl : 'templates/tmpl-isolated-scope-fun.html',
scope : {
//extSum : '&'
extSum : '&justSum'
},
controller : function($scope, $element, $attrs){
$scope.doProcess = function(){
$scope.extSum({m : $scope.x, n : $scope.y * ($scope.$parent.x)});
}
}
}
});