Javascript ng include适用于脚本部分,但不适用于单独文件中的部分
我从教程中复制了ng include的示例,但它似乎不起作用。我尝试将模板定义为脚本部分(如本教程的JSFIDLE中所述),但当我将它们作为单独的文件保存在同一文件夹中(Javascript ng include适用于脚本部分,但不适用于单独文件中的部分,javascript,html,angularjs,partials,Javascript,Html,Angularjs,Partials,我从教程中复制了ng include的示例,但它似乎不起作用。我尝试将模板定义为脚本部分(如本教程的JSFIDLE中所述),但当我将它们作为单独的文件保存在同一文件夹中(template1.html和template2.html)时,它停止工作 同样,我的代码与教程中的代码完全相同: index.html <!doctype html> <html ng-app> <head> <script src="http://code.angular
template1.html
和template2.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>
Content of template1.html
Content of template2.html
template2.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>
Content of template1.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上尝试此操作造成的。有关您编写的代码问题的问题必须描述具体问题,并包括重现该问题的有效代码。请包括代码/错误。没有人想为您的学习探索整个教程,谢谢。错误仅仅是模板未包含在内。请查看浏览器发出的请求,可能是服务器路径不正确,或者url绑定不起作用。创建一个自己的文件。