2016-06-22 34 views
0

我現在用的是繁重的任務grunt-angular-templates在我的應用程序,這導致輸出這樣的預編譯的角度模板:

$templateCache.put('src/ng-app/views/story/page.html', 
    //...html 

,但是這條線路上的模板投擲404文件

.when('/:pageId.aspx', { 
    templateUrl: 'src/ng-app/views/story/page.html', 

我看到另一篇文章有​​關設置模板的ID,並指定在路線,但我不知道該怎麼做,對於外部文件 - 例如使用這樣的內聯模板:

<script type="text/ng-template" id="login.html"> 
    login.html 
</script> 
+0

您是否爲templateCache指定了模塊名稱並將其作爲依賴項包含在您的應用中? –

+0

這很有趣,因爲我在旅途中有兩個應用程序,我將其添加到一個而不是另一個,似乎沒有任何區別。造成這種差別的原因是視圖腳本的順序 - 在我做出路由聲明之前必須先執行 –

回答

0

到底的簡單的解決方案 - 我必須確保由ngTemplates生成的視圖腳本之前路線聲明被包括(ⅰ有那些在單獨的腳本routes.js

其也是關鍵,以確保模塊是同樣在ngTemplates咕嚕:

var app = angular.module('MyApp.Web'... 

ngtemplates: { 
     app: { 
      src: 'src/ng-app/views/**/*.html', 
      dest: 'dist/src/js/ng-views.js', 
      options: { 
       module: 'MyApp.Web' 
      } 
     } 
    } 

添加模板作爲一個依賴再沒明顯的差異(如我在另一篇文章中找到):

angular.module('templates', []); 
var app = angular.module('MyApp.Web', [ 
    'ngRoute', 
    'youtube-embed', 
    'templates' 
]);