パラメータをサービス関数に送ることができます。約束事でAngularJSの関数にパラメータを渡す方法
getQuestions:関数(stateCode):questionResource.js
stateCodeがdtoResource.rc1Step1DTOの応答(から$の範囲に設定されている)の状態コードを渡す方法
angular
.module('autoQuote')
//Do initalization on page load
.run(['$log', '$rootScope', '$state', 'dtoResource', 'questionResource', function($log, $rootScope, $state, dtoResource, questionResource) {
$log.info('Post DTO on page load.');
dtoResource.rc1Step1DTO()
.then(questionResource.getQuestions)
.then(function(questions) {
$rootScope.questions = questions;
console.log('Obtained questions. Assigned to rootscope');
})
.then(function() {
console.log('This should be printed after the above methods are done executing');
console.log($rootScope);
});
}])
他の機能。 範囲内での位置が
$scope.postAutoQuoteObj.SessionInfo.StateCode
以下であるhttp://plnkr.co/edit/Op1QDwUBECAosPUC7r3N?p=preview
あなたのコントローラにも存在する前に、あなたの 'ラン()'関数が実行され、あなたが話している '$のscope'は、'ラン() '関数内からはアクセスできません。私は最初に物流を解決する必要があると思います。 – JLRishe
私が.runに書いた関数domのロード後に実行したいのですが、これらのメソッドは独立していて、同期した順序でなければなりません。あなたは私が何をすべきかをお勧めしますか?パラメータ・パスの問題に取り組む前に。 –