2014-09-10 25 views
0

我的web應用程序有許多視圖(模板),並且沒有靜態模式僅僅從路由參數組成templateUrl。 考慮到更新路由的靈活性,我將路由表存儲在SQL服務器中,並創建一個RESTful Web服務來檢索&更新路由模板記錄。 但是,在配置期間,我找不到在AngularJS中調用$ http和$ rootScope的方法。

我明白.config在.run之前發生在AngularJS中。在配置中,我們只能訪問常量和提供程序。 但是由於我使用的是templateUrl函數,函數體在運行時被調用。 我在想,如果有任何的方式來注入$ http和我templateUrl功能$ rootScope這將在運行短語執行...

angular.module('app', ['ngRoute']).config(['$routeProvider', 

     function ($routeProvider) { 

      $routeProvider. 
        when('/:param1/:param2/:param3', 
        { templateUrl: function(element){ 
         // $http GET routing table from RESTful API 
         // store the table to $rootScope 
         // look up table with param1+param2+param3 as key, get template url 
         return templateUrlFromTable ; 
        }}). 

        otherwise({redirectTo: '/'}); 

     }]) 

我很新的AngularJS,任何其他建議也受歡迎。 另外,如果我的理解錯誤,請糾正我。 謝謝。

+0

相關:http://stackoverflow.com/questions/15286588/how-to-inject-dependency-into-module-configconfigfn-in-angular – alecxe 2014-09-10 18:04:09

+0

謝謝。從相關文章中,我認爲我原來的問題的答案是'不'。我應該在JavaScript文件或服務器路由中使用服務器呈現的路由。 – 2014-09-15 16:38:22

回答