GET 요청에 응답하여 내 angularjs 앱을 초기화 할 수 있습니까? 예를 들어
: -
angular.module('A',[]);
angular.module('A').run(function ($rootScope,$http){
$rootScope.safeApply = function (fn) {
$http.get('url').success(function(result){
// This doesn't work. I am not able to inject 'theConstant' elsewhere in my application
angular.module('A').constant('theConstant', result);
});
var phase = $rootScope.$$phase;
if (phase === '$apply' || phase === '$digest') {
if (fn && (typeof (fn) === 'function')) {
fn();
}
} else {
this.$apply(fn);
}
};
});
내 응용 프로그램 초기화다면 상수를 설정하고 내 구성 요소에 상수를 공유 할 수 있어야합니다.
이 작업을 수행하는 가장 좋은 방법은 무엇입니까?
'theValueFromHttpCall' 무엇인가? – akonsu
@akonsu 질문이 업데이트되었습니다. 필자의 경우 reponse는 JSON 객체입니다. –
흥미 롭습니다. 인젝터에는 부팅 할 때 이미 정의 된 모든 구성 요소가 포함되어 있으므로 시나리오를 사용하려면 직접 함께 작업해야한다고 생각합니다. – akonsu