Wesley Cho
Software Engineer
Agile and Simplicity

app.controller('AbusiveCtrl', function ($scope, $rootScope, $http) {
$scope.clickHandler = function () {
$http.get('/data/from/file.json')
.then(function (response) {
var data = response.data;
$rootScope.state = !!data.completed;
$rootScope.$broadcast('data:received', data);
});
};
});app.factory('AbusiveService', function ($http, $rootScope) {
return {
getData: getData
};
function getData() {
return $http.get('data/from/file.json')
.then(function (response) {
var data = response.data;
$rootScope.state = !!data.completed;
$rootScope.$broadcast('data:received', data);
return data;
});
}
}).controller('AbusiveCtrl', function ($scope, AbusiveService) {
$scope.clickHandler = AbusiveService.getData;
});import {myUser as User} from 'my/models/user';
class Users {
constructor(http) {
this._cache = new Map();
this._http = http;
}
getById(id) {
return this._http.get('/users/' + id)
.then(this._cacheUser);
}
_cacheUser(response) {
var user = new User(response.data.user);
this._cache[user.id] = user;
return user;
}
}import {Inject} from 'di/index';
import {myHttpResponse as HttpResponse} from 'my/foundation/httpResponse';
import {myHttp as Http} from 'my/core/api';
import {myUser as User} from 'my/models/user';
@Inject(Http);
class Users {
_cache: map;
_http: Http;
constructor(http: Http) {
this._cache = new Map();
this._http = http;
}
getById(id) {
return this._http.get('/users/' + id)
.then(this._cacheUser);
}
_cacheUser(response: HttpResponse) {
var user = new User(response.data.user);
this._cache[user.id] = user;
return user;
}
}import {myUsers as Users} from 'my/models/Users';
import {myPosts as Posts} from 'my/models/Posts';
import {myPosts as Comments} from 'my/models/Comments';
angular.module('my.app')
.factory('Users', Users)
.factory('Posts', Posts)
.factory('Comments', Comments);angular.module('my.app')
.controller('HomeCtrl', function ($state, Home) {
this.ctrl = Home;
this.goToPost = function (post) {
post.get()
.then(function () {
$state.go('post', { id: post.id });
});
};
})
.controller('PostCtrl', function ($state, Post) {
this.ctrl = Post;
});<div class="scroll-container">
<div pull-to-refresh="home.ctrl.posts.get().then(home.refresh)"></div>
<div ng-repeat="post in home.ctrl.posts._posts">
<list-post post="post" go-to="home.goToPost"></list-post>
</div>
<div load-more="home.ctrl.posts.getMore().then(home.update)"></div>
</div>By Wesley Cho
Service-oriented Architecture with Angular.js - keeping agile and simple.