Skip to content

Commit 403aad1

Browse files
committed
adds attribute directives
1 parent fa0b6c1 commit 403aad1

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

03-1-directives.html

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,28 @@
1313
var app = angular.module("myApp", []);
1414
app.directive("calculator", function(){
1515
return {
16-
restrict : "E",
16+
restrict : "E",//E for element
1717
template:"<img src='http://www.stat.osu.edu/~stated/images/calculator.gif'>"
1818
};
1919
});
20+
21+
app.directive("leak", function(){
22+
return {
23+
restrict:"A",//A for attribute
24+
link:function(){
25+
alert("spray!");
26+
}
27+
}
28+
});
2029
</script>
2130

2231
</head>
2332
<body ng-app="myApp">
2433
<div id="wrapper">
2534
<calculator></calculator><br />
26-
<calculator></calculator>
35+
<!--Here we give our calculator attribute the leak attribute which executes the linking function.
36+
We could have just as well added the attribute to any other element-->
37+
<calculator leak></calculator>
2738
</div>
2839
</body>
2940
</html>

0 commit comments

Comments
 (0)