gpt4 book ai didi

dart - 如何在Dart中的html模板中获取RouteDefinition的AdditionalData

转载 作者:行者123 更新时间:2023-12-03 03:40:37 25 4
gpt4 key购买 nike

我正在尝试在var另外的数据中定义路由的页面名称,但是我不知道如何在html模板中获取此值。

static final unidadeFederativa = RouteDefinition(
routePath: RoutePaths.unidadeFederativa,
component: unidade_federativa_list_template.UnidadeFederativaListComponentNgFactory,
additionalData: { "pageName": "Unidade Federativa"}
);

<material-content>
<header class="material-header shadow">
<div class="material-header-row">
<material-button icon class="material-drawer-button" (trigger)="drawer.toggle()">
<material-icon icon="menu"></material-icon>
</material-button>
<span class="material-header-title">{{pageName}}}</span>
<div class="material-spacer"></div>
</div>
</header>
<div class="app-content">
<router-outlet [routes]="Routes.all"></router-outlet>
</div>
</material-content>

最佳答案

为了访问在路由定义中传递的AdditionalData,必须首先在组件中对其进行检索。

route.dart:

 static final all = <RouteDefinition>[
home,
RouteDefinition(
path: '.+',
component: not_found_template.NotFoundComponentNgFactory,
additionalData:{ "status": "404", "error": "Not Found" }
),
];

not_found_component.dart
class NotFoundComponent implements OnActivate {        

final Router _router;
NotFoundComponent(this._router);

var status;

@override
void onActivate(RouterState previous, RouterState current) {
// To retrieve normal queryParams :
// var queryParams = current.queryParameters;
// To retrieve the additional data you posted (check if exists)
this.status = current.routePath.additionalData.status;
}
}

然后,您可以在组件的模板中显示数据:
<div>
<h1>{{status}}</h1>
</div>

关于dart - 如何在Dart中的html模板中获取RouteDefinition的AdditionalData,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56459777/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com