forked from zafarali/learning-angular
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy path06-1-templatecache.html
37 lines (34 loc) · 970 Bytes
/
06-1-templatecache.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
<!DOCTYPE html>
<html>
<head>
<title>TemplateUrl</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.11/angular.min.js"></script>
<script>
var app = angular.module('myApp', []);
app.run(function($templateCache){
//this inserts something into the template cache
$templateCache.put('partial2.html', '<div><h3 ng-click="toggleContent()">{{title}} - click to see more</h3><div ng-show="isContentVisible">Hello friends</div></div>');
//this retrieves something from the tempalte cache
console.log($templateCache.get('partial2.html'));
});
app.directive('book', function(){
return {
restrict:'E',
scope:{title:'@'},
templateUrl:'partial2.html',
link: function(scope){
scope.isContentVisible = false;
scope.toggleContent = function(){
scope.isContentVisible = !scope.isContentVisible;
}
}
}
});
</script>
</head>
<body>
<div ng-app='myApp'>
<book title="welcome"></book>
</div>
</body>
</html>