1
app.factory('actfactory', function ($http) {
var myservice = {
result: [],
getdata: function() {
$http.get('api calll !!')
.success(function (response) {
console.log(response.data);
myservice.result.push(response.data);
}).error(function() {
if (window.localStorage.getItem("activity") !== undefined) {
self.results.push(JSON.parse(window.localStorage.getItem("activity")));
}
alert("please check your internet connection for updates !");
});
}
};
這是我的控制器服務和控制器angular.js
app.controller("activity", function ($scope,actfactory) {
$scope.activityresult = actfactory.getdata();
console.log($scope.activityresult);
});
雖然控制器做的console.log()在我得到空的對象! 和我的服務是控制檯返回罰款響應?
如何獲得的結果在服務