我編輯調用數據對離子我的代碼如何使用API
.factory('ProductsService',['$ionicSideMenuDelegate', '$http', 'ApiEndpoint', '$ionicTabsDelegate', '$ionicSlideBoxDelegate', '$stateParams', 'AuthService', function($ionicSideMenuDelegate, $http, ApiEndpoint, $ionicTabsDelegate, $ionicSlideBoxDelegate, $stateParams, AuthService){
var products = [];
var prod = [];
return {
GetProducts: function(){
return $http.get(ApiEndpoint.url + '/products', {}).then(function(response){
products = response.data.products;
return response;
});
},
GetProduct: function(productId){
angular.forEach(products, function(product, key){
$scope.prod = {}; //ERROR: $scope is not defined
if(product.id == productId){
prod = product;
return product;
}
})
return prod;
}
}
}])
..after我點擊錯誤appears..And頁面犯規顯示細節必須顯示的項目..
您是否在尋找服務?有關此主題的許多以前的帖子:http://stackoverflow.com/questions/20181323/passing-data-between-controllers-in-angular-js http://stackoverflow.com/questions/12008908/angularjs-how- can-i-pass-variables-between-controllers http://stackoverflow.com/questions/22408790/angularjs-passing-data-between-pages – BatteryAcid
你的GetProducts方法需要返回一個promise。目前它什麼都不做。把'$ http.get'改成'return $ http.get' –
嗨@Andrew McGivery我編輯了我的問題你能幫我嗎?謝謝 – RH34Serenity