Skip to content

Commit be7a82c

Browse files
committed
Added boilerplate for components, services, and directives
1 parent 47f5a23 commit be7a82c

File tree

7 files changed

+68
-2
lines changed

7 files changed

+68
-2
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export default class esCapitilize {
2+
construtor () {
3+
return {
4+
restrict: 'A'
5+
};
6+
}
7+
8+
link (scope, element) {
9+
element.html(toTitleCase(element.html()));
10+
}
11+
}
12+
13+
function toTitleCase (str) {
14+
return str.replace(/\w\S*/g, function (txt) { return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); });
15+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import templateUrl from 'home/counter.html';
2+
3+
class controller {
4+
constructor () {
5+
6+
}
7+
}
8+
9+
export default {
10+
controller,
11+
templateUrl,
12+
bindings: {
13+
count: '<count'
14+
}
15+
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export default class GitHubService {
2+
constructor ($resource) {
3+
'ngInject';
4+
var githubService = $resource(
5+
'https://api.github.com/users/',
6+
{},
7+
{
8+
'getRepos': {
9+
method: 'GET',
10+
url: 'https://api.github.com/users/nearbycoder/repos',
11+
isArray: true
12+
}
13+
}
14+
);
15+
16+
return githubService;
17+
}
18+
};
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
export default class HomeController {
2-
constructor () {
2+
constructor (githubService) {
33
'ngInject';
4+
5+
githubService.getRepos().$promise.then(results => {
6+
this.repos = results;
7+
this.count = results.length;
8+
});
49
}
510

611
}

src/app/components/home/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@ import uirouter from 'angular-ui-router';
33
import ngResource from 'angular-resource';
44
import routing from './home.routes.js';
55
import HomeController from './home.controller.js';
6+
import esCapitilize from './capitilize.directive.js';
7+
import esCounter from './counter.component.js';
8+
import GithubService from './github.service.js';
69

710
export default angular.module('app.home', [uirouter, ngResource])
811
.config(routing)
912
.controller('HomeController', HomeController)
13+
.directive('esCapitilize', () => new esCapitilize())
14+
.component('esCounter', esCounter)
15+
.service('githubService', GithubService)
1016
.name;

src/public/views/home/counter.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div>
2+
<span es-capitilize>The number of repos is</span> {{$ctrl.count}}
3+
</div>

src/public/views/home/home.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
testing
1+
<es-counter count="$ctrl.count"></es-counter>
2+
3+
<div ng-repeat="repo in $ctrl.repos">
4+
<span>{{repo.name}}</span>
5+
</div>

0 commit comments

Comments
 (0)