我已经使用typescript和angular js实现了一个模块,其中我有多个页面,我想每页使用一个打字稿控制器。我怎么能在我的路线中定义它们,因为我现在只定义了一个但是如果我也有6到7个控制器和页面。我在下面显示了我的代码: -
/// <reference path="../scripts/typings/angularjs/angular.d.ts" />
/// <reference path="../scripts/typings/angularjs/angular-route.d.ts" />
module CustomerSearch {
export class Routes {
static $inject = ["$routeProvider"];
static configureRoutes($routeProvider: ng.route.IRouteProvider) {
$routeProvider.when("/search", {
templateUrl: "search.aspx",
controller: "CustomerSearch.controllers.CustomerCtrl"
});
$routeProvider.otherwise({ redirectTo: "/search" });
}
}
}
答案 0 :(得分:1)
使用以下语法:
$routeProvider.
when("/search", {
templateUrl: "search.aspx",
controller: "CustomerSearch.controllers.CustomerCtrl"
}).
when('/home', {
templateUrl: "home.aspx",
controller: "ControllerName"
}).
when('/contact', {
templateUrl: "contact.aspx",
controller: "ControllerName"
}).
otherwise({
redirectTo: "/search"
});
&#13;
答案 1 :(得分:1)
让他们与$routeProvider.when
/// <reference path="../scripts/typings/tsd.d.ts" />
module CustomerSearch {
export class Routes {
static $inject = ["$routeProvider"];
static configureRoutes($routeProvider: ng.route.IRouteProvider) {
$routeProvider
.when("/search", {
templateUrl: "search.aspx",
controller: "CustomerSearch.controllers.CustomerCtrl"
})
.when("/home", {
templateUrl: "partials/home.aspx",
controller: "home.controller"
});
$routeProvider.otherwise({ redirectTo: "/search" });
}
}
}
&#13;