Angular 路线未显示视图

Angular route not showing view

我在设置路线时遇到问题:

angular_app.config(function($routeProvider){
    $routeProvider.when('Title', {
        controller : 'TitleController',
        templateUrl : 'app/html/Title.html'
    }).otherwise({
        redirectTo : 'Title'
    });
});

这不会正确触发,但是如果我这样编辑:

angular_app.config(function($routeProvider){
    $routeProvider.when('/', {
        controller : 'TitleController',
        templateUrl : 'app/html/Title.html'
    }).otherwise({
        redirectTo : 'Title',
        controller : 'TitleController',
        templateUrl : 'app/html/Title.html'
    });
});

它确实触发了我的控制器,但它触发了两次。为什么它不适用于第一种情况?

我的应用程序将在我的 Title.html 文件中有它的入口点。

有什么建议吗?

需要仔细阅读文档。

第一个参数必须是带有前导 / 的路径。另外 redirectTo 也应该是已经在 when()

中声明的路径
angular_app.config(function($routeProvider){
    $routeProvider.when('/title', {
        controller : 'TitleController',
        templateUrl : 'app/html/Title.html'
    }).otherwise({
        redirectTo : '/title'            
    });
});

您应该将代码更改为这个。

angular_app.config(function($routeProvider){
$routeProvider.when('/title', {
    controller : 'TitleController',
    controllerAs: 'Title',
    templateUrl : 'app/html/Title.html'
}).otherwise({
    redirectTo : '/title'            
});});