angular.module('myApp.services', ['ngResource']).
factory('Imgur', function($resource, $http) {
$http.defaults.useXDomain = true;
$http.defaults.headers.common['Authorization'] = 'Client-ID 123123123123';
var albumsService = {};
var albums = $resource('https://api.imgur.com/3/account/me123/albums').get();
//I can access albums.data in ng-repeate in view, but not here?
//returns undefined
console.log(albums.data);
albumsService.albums = function() {
return albums;
};
return albumsService;
});
使用这个作品
<ul class="nav nav-pills">
<li ng-repeat="album in imgur.albums().data">
{{album.title}}
</li>
</ul>