Javascript 如何通过url路径将angularjs重定向到模板?
我想根据Javascript 如何通过url路径将angularjs重定向到模板?,javascript,angularjs,Javascript,Angularjs,我想根据url显示内容。路径localhost:8080/test1应显示来自不同于localhost:8080/test2等模板的内容 但是下面的方法不起作用,我得到了一个404。为什么? var app = angular.module('myapp', ['ngRoute']); app.config(function($routeProvider, $locationProvider) { $routeProvider.when("/test1", { temp
url
显示内容。路径localhost:8080/test1
应显示来自不同于localhost:8080/test2
等模板的内容
但是下面的方法不起作用,我得到了一个404
。为什么?
var app = angular.module('myapp', ['ngRoute']);
app.config(function($routeProvider, $locationProvider) {
$routeProvider.when("/test1", {
templateUrl : "./templates/test1.html",
controller : "test1Controller"
}).when("/test2", {
templateUrl : "./templates/test2.html",
controller : "test2Controller"
}).otherwise({
templateUrl : "./templates/error.html"
});
$locationProvider.html5Mode(true);
});
文件夹结构:
static/js/main.js (file above)
static/js/test1Controller.js
static/js/test2Controller.js
static/templates/test1.html
static/templates/test2.html
static/index.html
为什么要在模板名前面加上点“
”
,/templates/error.html
?因为main.js在/js
文件夹中,所以我先升一级到/static
,然后进入/templates
。不管怎么说,去掉这个点没有什么区别,仍然可以得到404。怎么样/static/templates/test2.html
?
不会上升一级-你需要。
,不是吗?此外,URL是相对于index.html
(或应用程序拥有的任何页面),而不是相对于.js
文件OK,但是/templates/…
应该可以工作,但它不能工作。