我想打電話給工廠的控制器http
功能,它不會當我使用.then
我的代碼如下工作:的Http功能的控制器使用的時候不工作「然後」
模塊:
var brandlistmodule = angular.module('newApp
「)
工廠:
brandlistmodule.factory('BrandListFactory',["$http","$routeParams",function($http,$routeParams){
console.log(2)
return {
a: function(response){
console.log('1');
return $http.get("/restful_api/category_1/?format=json").then(function(response){
console.log('3');
return response.data;
});
},
b: function(response){
return $http.get("/restful_api/category_refer_a/?format=json").then(function(response){
return response.data;
});
},
c: function(response){
return $http.get("/restful_api/brand_test_search/?format=json").then(function(response){
result = response.data
return result;
});
},
}
}])
控制器:
brandlistmodule.controller('brandlistCtrl', ['BrandListFactory','$scope','$rootScope','$http',function (BrandListFactory,$scope,$rootScope,$http) {
$scope.$on('$viewContentLoaded', function() {
$rootScope.category = function(){
BrandListFactory.a.success(function(data){
console.log('9');
$rootScope.category =data
});
};
在它只能顯示「2」控制檯,如果我改變控制器如下,它會正常工作
brandlistmodule.controller('brandlistCtrl', ['BrandListFactory','$scope',function (BrandListFactory,$scope) {
$scope.$on('$viewContentLoaded', function() {
BrandListFactory.BrandCategoryList()
我非常感謝您的患者解釋,我已經用您的幫助解決了這個問題。謝謝 –
如果它對您有幫助的話..很高興!!! .. thnx –