forked from zafarali/learning-angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path03-1-directives.html
More file actions
50 lines (45 loc) · 1.21 KB
/
03-1-directives.html
File metadata and controls
50 lines (45 loc) · 1.21 KB
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
<!DOCTYPE html>
<html>
<head>
<title>directives</title>
<style>
*{font-family: Tahoma; font-size: 1em;}#wrapper{width:100%;};
#inner{width:50%; margin:0 auto; border:solid black 1px;};
</style>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js"></script>
<script>
var app = angular.module("myApp", []);
app.directive("calculator", function(){
return {
restrict : "E",//E for element
template:"<img src='http://www.stat.osu.edu/~stated/images/calculator.gif'>"
};
});
app.directive("leak", function(){
return {
restrict:"A",//A for attribute
link:function(){
alert("spray!");
}
}
});
app.directive("calculus", function(){
return {
restrict:"C",//C for class
link:function(){
alert("lets do some integration!")
}
}
});
</script>
</head>
<body ng-app="myApp">
<div id="wrapper">
<!--Here we give one of our calculators the calculus class.-->
<calculator class="calculus"></calculator><br />
<!--Here we give our calculator attribute the leak attribute which executes the linking function.
We could have just as well added the attribute to any other element-->
<calculator leak></calculator>
</div>
</body>
</html>