2017-04-12 52 views
1

有人能帮助,路线不工作也不加载HTML视图路线不工作也不加载HTML视图

https://plnkr.co/edit/yN1gi4urwWczedcCilbD

var hallApp = angular.module("hallApp",['ngRoute']); 

hallApp.config(['$routeProvider', function($routeProvider) { 
    $routeProvider.when('/home', { 
     templateUrl: 'home.html', 
     controller: 'homeCtrl' 

    }).when('/income', { 
     templateUrl: '../../views/income.html', 
     controller: 'incomeCtrl', 
     css: '../../css/income.css' 
    }).when('/expense', { 
     templateUrl: '../../views/expense.html', 
     controller: 'expenseCtrl', 
     css: '../../css/expense.css' 
    }).when('/profitandloss', { 
     templateUrl: '../../views/profitandloss.html', 
     controller: 'profitandlossCtrl', 
     css: '../../css/profitandloss.css' 
    }).otherwise({ 
     redirectTo: '/home' 
    }); 

}]); 

hallApp.controller('homeCtrl', ['$scope', function($scope) { 
    $scope.greeting = 'Home!'; 
}]); 

有人能帮助,路线不工作也不加载HTML视图

回答

2

在你Plunkr,你正在重新定义HallApp,所以你的路由消失:

var hallApp = angular.module("hallApp",['ngRoute']); // <- first define 

hallApp.config(...); 

hallApp.controller('homeCtrl', ['$scope', function($scope) { 
    $scope.greeting = 'Home!'; 
}]); 

var hallApp = angular.module('hallApp', []); // <- second define 
hallApp.controller('newCtrl', function($scope) { 
// create a message to display in our view 
$scope.message = 'Everyone come and see how good I look!'; 
}); 

删除“第二个定义”,你会没事的(固定Plunkr here)。


:在角,语法:

angular.module('app', []) 

angular.module('app') 

具有不同的含义。第一个创建一个新模块,第二个返回对现有模块的引用。所以应该只有一个调用模块(字符串,数组)与相同的字符串!