Angular js:如何在.run方法中调用控制器

时间:2016-07-13 05:54:11

标签: javascript jquery html angularjs

我正在开发角度js的Web应用程序 我想做一些顺序执行功能。

  

quoteController.js

(function () {
    "use strict";

 angular
    .module("autoQuote")
        //Do initalization on page load
       .run(["$log","$rootScope","$state","dtoResource","questionResource",function($log,$rootScope,$state,dtoResource,"questionResource") { 
          $rootScope.AutoQuote = dtoResource.rc1Step1DTO();
          $rootScope.questions = questionResource.getQuestions($rootScope.AutoQuote.postAutoQuoteObj.SessionInfo.StateCode);
          console.log($rootScope);
          $rootScope.$on("$stateChangeSuccess", function(event, toState, toParams, fromState, fromParams) {
            if (fromState.name === "") { 

            }
          });
        }])
}()); 

questionsCtrl.js

(function () {
"use strict";

angular
.module("autoQuote")
.factory("questionResource",["$resource","$http","$state",questionResource]);

function questionResource($resource,$http,$state)
{   
    return{
     getQuestions : function(stateCode) {
         var userState = stateCode != "" ? stateCode : 'CA';
         $http.get('assets/themes/easyquote/js/questions/'+userState+'.json')
         .then(function(response) {
            return response.data;  
        }); 
    }
   }
}

}());

在.run我想执行 $rootScope.AutoQuote = dtoResource.rc1Step1DTO();$rootScope.questions = $rootScope.questionsCtrl();

  1. rc1Step1DTO执行完成并成功时,只应启动questionsCtrl执行。

  2. 我无法从.run执行questionsCtrl函数。是说功能未定义。

  3. 请让我知道如何处理角度js中的这种情况。

0 个答案:

没有答案