2014-09-27 4 views
0

에 정의되지 않은 나는 3 개 개의 파일이 있습니다

는 app.js

angular.module("starweb", ["ngRoute", "ngAnimate", "ui.bootstrap"]) 
     .config(function ($routeProvider) { 
     $routeProvider .... 

addHostingController.js

angular.module("starweb") 
    .controller("addHostingCtrl", function ($scope, domainService) { 
     $scope.data.domains = domainService.getDomain(); 
} 

domainService.js

angular.module("starweb") 
.constant("domainList", "http://localhost:15536/api/product/xxxx") 
.service("domainService", function ($http, $q,domainList) { 
    return ({ 
     getDomain: GetDomains() 
    }); 
}); 

function GetDomains() { 
    $http.get(domainList).then(handleSuccess, handleError); 
} 

페이지 소스에는 3 개의 파일이 모두 포함됩니다 (app.js 첫 번째). Chrome에 $http is undefined이 표시됩니다. 설정에 문제가 있습니까?

감사합니다.

답변

2

domainService 범위에는 $http 서비스를 삽입 한 기능이 없습니다.

당신은 이런 식으로 코드를 변경해야합니다

.service("domainService", function ($http, $q, domainList) { 
    return { 
    getDomain: function (handleSuccess, handleError) { 
     $http.get(domainList).then(handleSuccess, handleError); 
    } 
    }; 
}); 

당신은 또한 당신의 getDomain 함수의 매개 변수로 확실히는 handleSuccesshandleError 콜백을 정의해야합니다.

+0

오, 감사합니다. –

관련 문제