var app = angular.module('MyApp', ['ngRoute']);
app.config(function ($routeProvider) {
$routeProvider
.when("/Home", {
templateUrl: "Home/EmployeeList",
controller: "listController",
})
.when("/Home1", {
templateUrl: "Home/EmployeeTable",
controller: "tableController",
})
.otherwise({
redirectTo: "/Home/Index"
})
.controller("listController", function ($scope) {
$scope.message = "In list controller";
})
});
为什么运行代码TypeError:routeProvider.when(...)。when(...)。否则(...)。控制器错误显示在cosole中。
答案 0 :(得分:0)
将控制器注册调用移出配置块。没有$routeProvider.controller
var app = angular.module('MyApp', ['ngRoute']);
app.config(function ($routeProvider) {
$routeProvider
.when("/Home", {
templateUrl: "Home/EmployeeList",
controller: "listController",
})
.when("/Home1", {
templateUrl: "Home/EmployeeTable",
controller: "tableController",
})
.otherwise({
redirectTo: "/Home/Index"
})
});
app.controller("listController", function ($scope) {
$scope.message = "In list controller";
})