-
Notifications
You must be signed in to change notification settings - Fork 55
/
04-2-scope.html
39 lines (35 loc) · 952 Bytes
/
04-2-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
<!DOCTYPE html>
<html>
<head>
<title>scope</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.11/angular.min.js"></script>
<script>
var app = angular.module('foodApp',[]);
app.controller('Ctrl', function($scope){
$scope.data={
flavor:"coke"
}
});
app.directive('drink', function(){
return {
scope: {
flavor:"="
},
restrict: 'E',
template: '<div>From the directive scope: {{flavor.flavor}}. Edit this here: <input type="text" ng-model="flavor.flavor"></div>'
};
});
</script>
</head>
<body>
<div ng-app="foodApp" ng-controller='Ctrl'>
From the ctrl scope:{{data.flavor}}
<drink flavor="data"></drink>
<!--Only above will bind to scope as it is linked to the object data which is on the scope-->
From the ctrl scope:{{data.flavor}}
<drink flavor="{flavor:'sprite'}"></drink>
From the ctrl scope:{{data.flavor}}
<drink flavor="{flavor:'canada dry'}"></drink>
</div>
</body>
</html>