ng-include适用于脚本部分,但不适用于单独文件中的部分内容

时间:2013-07-04 12:02:54

标签: javascript html angularjs partials

我从教程ngInclude复制了ng-include的示例,但它似乎不起作用。我尝试将模板定义为脚本部分(如本教程的jsFiddle中所示),并且它可以工作,但是当我将它们作为单独的文件保存在同一文件夹(template1.htmltemplate2.html)中时,它会停止工作。

同样,我的代码完全如教程:

的index.html

<!doctype html>
<html ng-app>
  <head>
    <script src="http://code.angularjs.org/1.0.6/angular.min.js"></script>
    <script src="script.js"></script>
  </head>
  <body>
    <div ng-controller="Ctrl">
      <select ng-model="template" ng-options="t.name for t in templates">
       <option value="">(blank)</option>
      </select>
      url of the template: <tt>{{template.url}}</tt>
      <hr/>
      <div ng-include src="template.url"></div>
    </div>
  </body>
</html>

template1.html

Content of template1.html

template2.html

Content of template2.html

的script.js

function Ctrl($scope) {
  $scope.templates =
    [ { name: 'template1.html', url: 'template1.html'}
    , { name: 'template2.html', url: 'template2.html'} ];
  $scope.template = $scope.templates[0];
}

谢谢,

更新:

解决。问题显然是在Chrome上尝试这个问题造成的。

0 个答案:

没有答案
相关问题