如何通过url路径将angularjs重定向到模板?

时间:2015-09-16 09:32:34

标签: javascript angularjs

我想根据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

0 个答案:

没有答案