0
응용 프로그램 시작시에만 gloop 변수 "$ rootScope.SegmentSelectedGlobal"을 초기화하고 싶습니다. 이 globle 변수는 서비스에서 데이터를 가져옵니다. 컨트롤러를 통해 서비스를 실행하면 정상적으로 작동합니다. 그러나 App.run에서 실행할 때 아무런 값도보고되지 않고 오류가보고되지 않습니다.AngularJS : app.run에서 서비스 주입
App.run : 여기
코드입니다app.run(['$rootScope','DashboardService', function($rootScope,DashboardService) {
$rootScope.SegmentSelectedGlobal = DashboardService.getSegments();
}]);
서비스 : 당신의 도움에 대한
app.service("DashboardService",function($q,$http,errorMessages){
var allSegements = [];
return {
// For selected Only
getSegments : getSegments
}
function getSegments(){
var deferred = $q.defer();
$http({
url: "/getAllSegments",
method: "GET"
}).success(function (data, status, headers, config) {
deferred.resolve(data);
allSegements = data;
}).error(function (data, status, headers, config) {
//logger.logError('Error while retrieving Versions details');
allSegements = null;
});
return allSegements;
}
});
고맙습니다.
@Walfrat. 지금은 일하고 .. !! – Bond