【发布时间】:2015-06-25 13:52:37
【问题描述】:
通常我会在路线中添加一些设置。例如:
.when('Products', {
templateUrl: 'App/Products.html',
settings: {
showbuy: true,
showexport: true,
Description: "Product List"
},[...]
自从我开始使用 TypeScript 和 angularJS 以来,IRouteProvider 的接口给 IRouteProvder 带来了一些限制。 IRoute 接口。 IRoute 接口没有提供任何可以存储我的自定义设置对象的属性。
目前我只能设置 IRoute 接口的预定义属性,例如:
app.config([
<any>'$routeProvider', function routes($routeProvider: ng.route.IRouteProvider) { $routeProvider
.when('/Product',
{
templateUrl: 'App/Products.html',
controller:'someController'
[...]
})
angular js ng-route 接口定义为:
interface IRouteProvider extends IServiceProvider {
otherwise(params: IRoute): IRouteProvider;
when(path: string, route: IRoute): IRouteProvider;
}
/**
* see http://docs.angularjs.org/api/ngRoute/provider/$routeProvider#when for API documentation
*/
interface IRoute {
/**
* {(string|function()=}
* Controller fn that should be associated with newly created scope or the name of a registered controller if passed as a string.
*/
controller?: string|Function;
/**
* A controller alias name. If present the controller will be published to scope under the controllerAs name.
*/
controllerAs?: string;
/**
* Undocumented?
*/
name?: string;
[...]
所以我问自己,是否存在将自定义对象保存到每个定义的路由的解决方法。
【问题讨论】:
标签: javascript angularjs typescript