-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathangular-service.js
More file actions
38 lines (37 loc) · 1.07 KB
/
angular-service.js
File metadata and controls
38 lines (37 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
angular.module('wpApi', []);
angular.module('wpApi')
.factory('wpService', function($http, $q) {
var wpUrl = SITEURL;
return {
posts: function(post) {
var delay = $q.defer();
var postNumber = post || '';
$http.get(wpUrl + 'posts/' + postNumber)
.success(function(data) {
delay.resolve(data);
});
return delay.promise;
}
};
})
.directive('getPosts', function(wpService) {
return {
template: '<md-list><md-list-item ng-repeat="post in posts">{{post.title.rendered}}</md-list-item></md-list>',
link: function($scope, elem, attrs) {
wpService.posts().then(function(data) {
$scope.posts = data;
});
}
};
})
.directive('getPost', function(wpService) {
return {
template: '<md-list><md-list-item>{{post.title.rendered}}</md-list-item></md-list>',
link: function($scope, elem, attrs) {
var post = attrs.number;
wpService.posts(post).then(function(data) {
$scope.post = data;
});
}
};
});