2014-12-04 83 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' 
    } 
    } 
});