Skip to content

Commit 0d2305f

Browse files
author
K.C. Hunter
committed
Adding tutorial on AngularJS Directive restrictions.
1 parent 61c5341 commit 0d2305f

3 files changed

Lines changed: 101 additions & 2 deletions

File tree

src/angularjstutorial.js

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,51 @@
11
/* use strict */
22
var app = angular.module('MyApp', []);
33

4-
app.controller('ShieldCtrl', function ($scope)
4+
app.directive('restrictions', function ()
5+
{
6+
return {
7+
restrict: 'A',
8+
link: function ()
9+
{
10+
console.log('I am an attribute');
11+
}
12+
}
13+
})
14+
15+
.directive('elementrest', function ()
16+
{
17+
return {
18+
restrict: 'E',
19+
link: function ()
20+
{
21+
console.log('I am an element');
22+
}
23+
}
24+
})
25+
26+
.directive('classrest', function ()
27+
{
28+
return {
29+
restrict: 'C',
30+
link: function ()
31+
{
32+
console.log('I am a class');
33+
}
34+
}
35+
})
36+
37+
.directive('commentsrest', function ()
38+
{
39+
return {
40+
restrict: 'M',
41+
link: function ()
42+
{
43+
console.log('I am a comment restriction');
44+
}
45+
}
46+
})
47+
48+
.controller('ShieldCtrl', function ($scope)
549
{
650
$scope.shieldNames = [];
751

src/index.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@
1313
<body>
1414

1515
<div class="mainContainer" data-ng-app="MyApp">
16+
17+
<div restrictions>Attribute Restriction</div>
18+
19+
<elementrest>Element Restriction</elementrest>
20+
21+
<div class="classrest">Class Restriction</div>
22+
23+
<!-- directive:commentsrest -->
24+
<div></div>
25+
26+
1627
<walterwhite message="I am Heisenberg" class="btn btn-default">
1728

1829
</walterwhite>

src/resources/js/myApp.js

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,51 @@
11
/* use strict */
22
var app = angular.module('MyApp', []);
33

4-
app.controller('ShieldCtrl', function ($scope)
4+
app.directive('restrictions', function ()
5+
{
6+
return {
7+
restrict: 'A',
8+
link: function ()
9+
{
10+
console.log('I am an attribute');
11+
}
12+
}
13+
})
14+
15+
.directive('elementrest', function ()
16+
{
17+
return {
18+
restrict: 'E',
19+
link: function ()
20+
{
21+
console.log('I am an element');
22+
}
23+
}
24+
})
25+
26+
.directive('classrest', function ()
27+
{
28+
return {
29+
restrict: 'C',
30+
link: function ()
31+
{
32+
console.log('I am a class');
33+
}
34+
}
35+
})
36+
37+
.directive('commentsrest', function ()
38+
{
39+
return {
40+
restrict: 'M',
41+
link: function ()
42+
{
43+
console.log('I am a comment restriction');
44+
}
45+
}
46+
})
47+
48+
.controller('ShieldCtrl', function ($scope)
549
{
650
$scope.shieldNames = [];
751

0 commit comments

Comments
 (0)