在drupal页面中找不到角度内联模板404

时间:2015-10-22 10:46:24

标签: javascript angularjs drupal-7 router angularjs-routing

我在drupal 7页面中提供角度路由器。同样的例子在这个小提琴中运行良好:http://jsfiddle.net/laurencefass/Lsu8p124/

HTML

<script type="text/ng-template" id="embedded.home.html">
  <h1> Home </h1>
</script>

<script type="text/ng-template" id="embedded.about.html">
  <h1> About </h1>
</script>

<div ng-app="routerApp"> 
  <div id="navigation">  
  <a href="#/home">Home</a>
  <a href="#/about">About</a>
  </div>
  <div ng-view></div>
</div>

的Javascript

var app=angular.module('routerApp', ['ngRoute']);

app.controller('HomeController', function ($scope) {});
app.controller('AboutController', function ($scope) {});
app.config(function ($routeProvider) {
    $routeProvider.
    when('/home', {
       templateUrl: "embedded.home.html",
       controller: 'HomeController'
    }).
    when('/about', {
       templateUrl: 'embedded.about.html',
       controller: 'AboutController'
    }).
    otherwise({
        redirectTo: '/home'
    });
});

我收到以下运行时错误:

“错误:[$ compile:tpload]无法加载模板:embedded.home1.html(HTTP状态:404未找到)   http://errors.angularjs.org/1.5.0-beta.1/ $编译/ tpload P0 = embedded.home1.html&安培; P1 = 404&安培; P2 =未%20Found   minErr /&LT; @ https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0-beta.1/angular.js?nwma5b:68:5   的HandleError @ https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0-beta.1/angular.js?nwma5b:17751:1   processQueue @ https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0-beta.1/angular.js?nwma5b:14814:11   scheduleProcessQueue /&LT; @ https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0-beta.1/angular.js?nwma5b:14830:27   。$ RootScopeProvider /这$ gethttps://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0-beta.1/angular.js nwma5b:16058:9 。$ RootScopeProvider /这$ gethttps://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0-beta.1/angular.js nwma5b:15869:15 。$ RootScopeProvider /这$ gethttps://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0-beta.1/angular.js nwma5b:16166:13 做@ https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0-beta.1/angular.js?nwma5b:10607:36 completeRequest @ https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0-beta.1/angular.js?nwma5b:10805:7 requestLoaded @ https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0-beta.1/angular.js?nwma5b:10750:1

1 个答案:

答案 0 :(得分:0)

脚本需要在ng-app div内部才能使内联脚本工作,否则angular会查找文件。不是最好的实现,也没有明确记录,但它适用于测试目的。 Using Inline Templates in Angular