TypeScript + AngularJs: - 如何在单个路径文件中定义多个路径

时间:2015-07-24 13:08:19

标签: angularjs typescript angular-routing typescript1.4 typescript1.5

我已经使用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" });
        }

        }
    }

2 个答案:

答案 0 :(得分:1)

使用以下语法:

&#13;
&#13;
$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;
&#13;
&#13;

答案 1 :(得分:1)

让他们与$routeProvider.when

联系起来

&#13;
&#13;
/// <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;
&#13;
&#13;