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