2014-12-04 81 views
0

實施例加載模板:

registry.html

<label>Name:</label> 

app.js

define(['angular', 'services','text', 
'text!ang/templates/registry.html'], function(angular, services,textmod,template) { 
    ........ 
     angular.module('myApp.directives', ['myApp.services']) 
     .directive('superd', function() { 
         return { 

           templateUrl:template, 
            .......... 
           } 
       }) 

Eror:

GET app_ang /%3Clabel%3名稱: %3C /標籤%3E 403(禁止) angular.js胸圍= 1417672731204137.41101580671966:10023

錯誤:[$編譯:tpload]未能加載模板:<label>Name:</label>

注: '文本' 是https://github.com/requirejs/text

+0

什麼是 「模板」 在你的指導值?它是動態的,那麼從哪裏來的價值? – Asik 2014-12-04 06:16:17

+0

我編輯過文章.... – 2014-12-04 06:19:18

+0

您是否嘗試直接在瀏覽器中訪問該頁面?另外,請查看請求的螢火蟲並複製該網址並直接在瀏覽器中點擊? – Asik 2014-12-04 06:24:59

回答

1

我不認爲你需要直接依賴'text'

define([ 
    'angular', 
    'services', 
    'text!ang/templates/registry.html' 
], function(angular, services, template) { 
    //... 
    angular.module('myApp.directives', ['myApp.services']) 
     .directive('superd', function() { 
      return { 
      templateUrl: template, 
      //... 
      }; 
     }); 

而在你需要的配置:

require.config({ 
    //... 
    paths: { 
    // path example if you are using bower 
    'angular': '/bower_components/angular/angular', 
    'text': '/bower_components/requirejs-text/text' 
    }, 

    shim: { 
    'angular': { 
     exports: 'angular' 
    } 
    } 
});