gpt4 book ai didi

dart - 使用服务作为装饰

转载 作者:行者123 更新时间:2023-12-03 03:42:32 24 4
gpt4 key购买 nike

有没有办法在加载前检查某些逻辑的路由上做静态装饰器?


有一个授权装饰器

@Injector()
class Auth{
Auth(){
if (isLoggedIn){
proceed();
}else{
showLoginRoute();
}
}
}

并使用像
@Auth()
@Component(
selector: 'auth-view',
styleUrls: const ['login_component.css'],
template:
'<router-outlet name="dashboard" [routes]="routes.authView_routes"></router-outlet>',
directives: const [materialDirectives, routerDirectives, coreDirectives],
providers: const [r.Routes, materialProviders, Auth],
)
class Dashboard{
....
}

我知道我想做什么,但是不确定如何完成它。目前,我正在跨多个组件导入服务并进行大量重复,我希望尽可能避免这种情况。

最佳答案

Dart不支持TS中的装饰器。

可能适合您的是代码生成,就像在build_valuejson_serializable,...中完成的一样。

https://github.com/dart-lang/build

关于dart - 使用服务作为装饰,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52237693/

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