Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.

Commit 149b9b5

Browse files
author
Erin Altenhof-Long
committed
feat(sampleApps): add directive examples to sample applications
Add good and bad uses of custom directives in example and correctExample to show more ngHint options for directives. #36
1 parent a2553ce commit 149b9b5

File tree

4 files changed

+44
-11
lines changed

4 files changed

+44
-11
lines changed

correctExample/app.css

+1
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,5 @@ h1 {
4343

4444
#contributors {
4545
list-style-type: none;
46+
-webkit-padding-start: 0px;
4647
}

correctExample/index.html

+18-4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ <h1> Angular Best Practices </h1>
3939
</table>
4040
</div>
4141

42+
<div bp-our-visitors info="erin"></div>
43+
4244
<ul id="contributors">
4345
App contributors:
4446
<li ng-repeat="contributor in contributors">
@@ -50,8 +52,8 @@ <h1> Angular Best Practices </h1>
5052
<script src="../bower_components/angular/angular.js"></script>
5153
<script src="../dist/hint.js"></script>
5254
<script>
53-
angular.module('bpAppModule', []);
54-
angular.module('bpAppModule').controller('BestPracticesController', ['$scope', function($scope) {
55+
angular.module('bpAppModule', [])
56+
.controller('BestPracticesController', ['$scope', function($scope) {
5557
$scope.types = [
5658
{ name: 'Controllers', practices: ['Do not use global controllers. Define controllers ' +
5759
'on modules.', 'Name controllers with UpperCamelCase.', 'Name controllers with the ' +
@@ -74,9 +76,21 @@ <h1> Angular Best Practices </h1>
7476
'modules that are not used.', 'Remember to load ngRoute if you are using routing.',
7577
'Only bootstrap one module with "ng-app".'], isChecked: false}
7678
];
77-
79+
$scope.erin = {
80+
name: 'Erin',
81+
bestPractice: 'Do not manipulate the DOM from within Angular Controllers.'
82+
};
7883
$scope.contributors = ['Me', 'You'];
79-
}]);
84+
}])
85+
.directive('bpOurVisitors', function() {
86+
return {
87+
restrict: 'A',
88+
template: '<br>Site Visitors:<br>Name: {{visitor.name}}. Favorite Best Practice: {{visitor.bestPractice}}',
89+
scope: {
90+
visitor: '=info'
91+
}
92+
};
93+
});
8094
</script>
8195
</body>
8296

example/app.css

+1
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,5 @@ h1 {
4343

4444
#contributors {
4545
list-style-type: none;
46+
-webkit-padding-start: 0px;
4647
}

example/index.html

+24-7
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,22 @@ <h1> Angular Best Practices </h1>
2121
<div ng-controller="bestPractices">
2222
<div id="whichBestPractices">
2323
Show Best Practices For:
24-
<form id="selectKind" action="">
24+
<div id="selectKind">
2525
<input type="checkbox" id="controllers" onclick="changeList()">Controllers</input>
2626
<input type="checkbox" id="directives" onclick="changeList()" checked>Directives</input>
2727
<input type="checkbox" id="DOM" onclick="changeList()">DOM</input>
2828
<input type="checkbox" id="events" onclick="changeList()">Events</input>
2929
<input type="checkbox" id="interpolation" onclick="changeList()">Interpolation</input>
3030
<input type="checkbox" id="modules" ng-click="changeList()">Modules</input>
31-
</form>
32-
31+
</div>
3332
</div>
3433

3534
<table id="bestPracticesList">
3635
</table>
3736

37+
<div ng-controller="Controller">
38+
<div our-visitors info="erin"></div>
39+
</div>
3840
<ul id="contributors">
3941
<li ng-reapet="contributor in contributors">
4042
{{contributor.name}}
@@ -45,9 +47,7 @@ <h1> Angular Best Practices </h1>
4547
<script src="../dist/hint.js"></script>
4648
<script>
4749
angular.module('bpAppModule', []);
48-
angular.module('AppModule2', []);
49-
angular.module('AppModule2', []).
50-
controller('bestPractices', ['$scope', function($scope) {
50+
function bestPractices($scope) {
5151
var bestPractices = {
5252
'controllers': ['Do not use global controllers. Define controllers ' +
5353
'on modules.', 'Name controllers with UpperCamelCase.', 'Name controllers with the ' +
@@ -86,7 +86,24 @@ <h1> Angular Best Practices </h1>
8686
}
8787
}
8888
$scope.contributors = ['Me', 'You'];
89-
}]);
89+
}
90+
91+
angular.module('AppModule2', []).controller('Controller', ['$scope', function($scope) {
92+
$scope.erin = {
93+
name: 'Erin',
94+
bestPractice: 'Do not manipulate the DOM from within Angular Controllers.'
95+
};
96+
}]);
97+
angular.module('AppModule2', []).directive('OurVisitors', function() {
98+
return {
99+
restrict: 'A',
100+
template: '<br>Site Visitors:<br>Name: {{visitor.name}}. Favorite Best Practice: {{visitor.bestPractice}}',
101+
scope: {
102+
visitor: '=info'
103+
},
104+
replace: true
105+
};
106+
});
90107
</script>
91108
</body>
92109

0 commit comments

Comments
 (0)