Skip to content

Commit cdb347b

Browse files
author
K.C. Hunter
committed
Part 7 added
1 parent 8504395 commit cdb347b

3 files changed

Lines changed: 164 additions & 6 deletions

File tree

src/angularjstutorial.js

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

4-
app.directive('interactiveBtn', function ()
4+
app.controller('ShieldCtrl', function ($scope)
5+
{
6+
$scope.shieldNames = [];
7+
8+
this.addReigns = function ()
9+
{
10+
$scope.shieldNames.push("Roman Reigns: Juggernaut");
11+
};
12+
13+
this.addRollins = function ()
14+
{
15+
$scope.shieldNames.push("Seth Rollins: Architect");
16+
};
17+
18+
this.addAmbrose = function ()
19+
{
20+
$scope.shieldNames.push("Dean Ambrose: Lunatic Fringe");
21+
};
22+
})
23+
24+
.directive('theshield', function ()
25+
{
26+
return {
27+
restrict: 'E',
28+
scope: {},
29+
controller: 'ShieldCtrl',
30+
link: function (scope, element, attrs)
31+
{
32+
element.bind('mouseenter', function ()
33+
{
34+
console.log(scope.shieldNames);
35+
});
36+
}
37+
}
38+
})
39+
40+
.directive('reigns', function ()
41+
{
42+
return {
43+
require: 'theshield',
44+
link: function (scope, element, attrs, ShieldCtrl)
45+
{
46+
ShieldCtrl.addReigns();
47+
}
48+
}
49+
})
50+
51+
.directive('rollins', function ()
52+
{
53+
return {
54+
require: 'theshield',
55+
link: function (scope, element, attrs, ShieldCtrl)
56+
{
57+
ShieldCtrl.addRollins();
58+
}
59+
}
60+
})
61+
62+
.directive('ambrose', function ()
63+
{
64+
return {
65+
require: 'theshield',
66+
link: function (scope, element, attrs, ShieldCtrl)
67+
{
68+
ShieldCtrl.addAmbrose();
69+
}
70+
}
71+
})
72+
73+
.directive('interactiveBtn', function ()
574
{
675
return {
776
restrict: 'A',
@@ -27,9 +96,9 @@ app.directive('interactiveBtn', function ()
2796
transclude: true,
2897
link: function (scope, element, attrs)
2998
{
30-
console.log(scope);
99+
/*console.log(scope);
31100
console.log(element);
32-
console.log(attrs);
101+
console.log(attrs);*/
33102
}
34103
}
35104
/*return {

src/index.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,29 @@
1414

1515
<div class="mainContainer" data-ng-app="MyApp">
1616
<walterwhite message="I am Heisenberg" class="btn btn-default"></walterwhite>
17+
<br>
18+
1719
<div interactive-btn class="btn btn-default">
1820
Button
1921
</div>
22+
<br>
23+
24+
<theshield reigns rollins ambrose class="btn btn-default">
25+
Access The Shield
26+
</theshield>
27+
28+
<theshield reigns class="btn btn-default">
29+
Click Reigns
30+
</theshield>
31+
32+
<theshield rollins class="btn btn-default">
33+
Click Rollins
34+
</theshield>
35+
36+
<theshield ambrose class="btn btn-default">
37+
Click Ambrose
38+
</theshield>
39+
2040
</div>
2141

2242
</body>

src/resources/js/myApp.js

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

4-
app.directive('interactiveBtn', function ()
4+
app.controller('ShieldCtrl', function ($scope)
5+
{
6+
$scope.shieldNames = [];
7+
8+
this.addReigns = function ()
9+
{
10+
$scope.shieldNames.push("Roman Reigns: Juggernaut");
11+
};
12+
13+
this.addRollins = function ()
14+
{
15+
$scope.shieldNames.push("Seth Rollins: Architect");
16+
};
17+
18+
this.addAmbrose = function ()
19+
{
20+
$scope.shieldNames.push("Dean Ambrose: Lunatic Fringe");
21+
};
22+
})
23+
24+
.directive('theshield', function ()
25+
{
26+
return {
27+
restrict: 'E',
28+
scope: {},
29+
controller: 'ShieldCtrl',
30+
link: function (scope, element, attrs)
31+
{
32+
element.bind('mouseenter', function ()
33+
{
34+
console.log(scope.shieldNames);
35+
});
36+
}
37+
}
38+
})
39+
40+
.directive('reigns', function ()
41+
{
42+
return {
43+
require: 'theshield',
44+
link: function (scope, element, attrs, ShieldCtrl)
45+
{
46+
ShieldCtrl.addReigns();
47+
}
48+
}
49+
})
50+
51+
.directive('rollins', function ()
52+
{
53+
return {
54+
require: 'theshield',
55+
link: function (scope, element, attrs, ShieldCtrl)
56+
{
57+
ShieldCtrl.addRollins();
58+
}
59+
}
60+
})
61+
62+
.directive('ambrose', function ()
63+
{
64+
return {
65+
require: 'theshield',
66+
link: function (scope, element, attrs, ShieldCtrl)
67+
{
68+
ShieldCtrl.addAmbrose();
69+
}
70+
}
71+
})
72+
73+
.directive('interactiveBtn', function ()
574
{
675
return {
776
restrict: 'A',
@@ -27,9 +96,9 @@ app.directive('interactiveBtn', function ()
2796
transclude: true,
2897
link: function (scope, element, attrs)
2998
{
30-
console.log(scope);
99+
/*console.log(scope);
31100
console.log(element);
32-
console.log(attrs);
101+
console.log(attrs);*/
33102
}
34103
}
35104
/*return {

0 commit comments

Comments
 (0)