1
我有一个angularJS工厂和控制器的问题 我想在工厂得到http回复并使用控制器中的api回复 但我不知道如何处理工厂并将其注入控制器注入控制器的工厂angularJS
.controller('PlaylistsCtrl', function ($scope, $http) {
$http({ method: 'GET', url: "https://www.googleapis.com/blogger/v3/blogs/1309320265504420965/posts?key=***************" }).
success(function (data, status, headers, config) {
// this callback will be called asynchronously
// when the response is available
for (var i =0; i < data.items.length;i++)
{
var m,
urls = [],
str = data.items[i].content,
rex = /(https?:\/\/.*\.(?:png|jpg))/g;
while (m = rex.exec(str)) {
urls.push(m[1]);
data.items[i].ImageURL = urls[0];
}
//data.items[i].ImageURL = urls[0];
}
$scope.playlists = data.items;
}).
error(function (data, status, headers, config) {
// called asynchronously if an error occurs
// or \\server returns response with an error status.
});
})
首先非常感谢你的快速回复 做什么你的意思是 $ scope.getData = function(){ apiService.get(“/ server/data”)。success(function(data) – 2014-09-01 20:50:19
这只是演示如何为所有外部API创建通用服务打电话的。 getData只是一个示例函数,展示了如何使用apiService返回的承诺。 – 2014-09-02 06:10:16