https://codepen.io/a_shokn/pen/yEJpww?editors=1010
var myApp = angular.module('myApp', ['ngRoute']);
myApp.config(function ($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'main.html'
})
.when('/second',{
templateUrl:'second.html'
})
});
这是指向我的代码片段的链接,我的问题是在 anjular js 中使用路由时,我们是否必须保留我们的文件(在我的情况下是主要的.html其次.html
根据我的理解,代码笔不支持添加多个文件。您可以尝试将代码移动到 plunker。或者,您可以尝试在 HTML 中使用内联模板。例如,要解决main.html
问题,您可以在 HTML 中编写以下代码片段:
<script type="text/ng-template" id="main.html">
// contents of main.html
</script>
这将使 AngularJS 使用此script
标签解析模板。您可以在此处找到代码的工作演示。