为什么providerRoute不工作

时间:2017-10-21 09:47:18

标签: angularjs asp.net-mvc

    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中。

1 个答案:

答案 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";
})