Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在AngularDart中,如何将预入站事件注册到需要使用服务方法的路由?_Dart_Angular Dart - Fatal编程技术网

在AngularDart中,如何将预入站事件注册到需要使用服务方法的路由?

在AngularDart中,如何将预入站事件注册到需要使用服务方法的路由?,dart,angular-dart,Dart,Angular Dart,在AngularDart中的所有弃用之后,现在通过模块构造函数中的以下initRoutes方法配置路由 //在应用程序的main中 .. bind(RouteInitializerFn,toValue:initRoutes); this.bind(NgRoutingUsePushState,toFactory:()=>newngroutingusepushstate.value(false)); //在routeconfig.dart文件中,该文件在main.dart中导入 void initR

在AngularDart中的所有弃用之后,现在通过模块构造函数中的以下initRoutes方法配置路由

//在应用程序的main中
..
bind(RouteInitializerFn,toValue:initRoutes);
this.bind(NgRoutingUsePushState,toFactory:()=>newngroutingusepushstate.value(false));
//在routeconfig.dart文件中,该文件在main.dart中导入
void initRoutes(路由器路由器、RouteViewFactory viewFactory){
viewFactory.configure({
“登录页面”:ngRoute(
路径:'/loginPage',
视图:“view/loginPage.html”),
“着陆页面”:着陆路线(
路径:'/landingPage',
视图:“view/landingPage.html”,
defaultRoute:对,
输入:\检查身份验证
...

我的问题是如何注入在routeconfig.dart中具有_checkAuthentication方法的服务类?既然它不是一个类,如何在这里获得依赖注入?或者是否有另一种方法在模块构造函数中初始化和注册RouteInitializerFn?

您可以使用以下技术:可以实现函数使用“call”方法以类的形式存储

@Injectable()
类MyRouteInitializer实现函数{
授权服务;
MyRouteInitializer(this.service);
调用(路由器路由器、RouteViewFactory viewFactory){
...
服务。_checkAuthentication();
...
}
}
模块中的功能注册:

this.bind(RouteInitializerFn,toImplementation:MyRouteInitializer);