Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.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
Angular 角度2使用服务路由_Angular_Angular2 Routing_Angular2 Services - Fatal编程技术网

Angular 角度2使用服务路由

Angular 角度2使用服务路由,angular,angular2-routing,angular2-services,Angular,Angular2 Routing,Angular2 Services,我想创建一个执行路由的服务。我想我需要路由器服务和路由器指令。我可以在我的服务中使用构造函数简单地注入路由器服务 如何添加路由器\u指令 Cheers必须在使用相应指令(如ROUTER outlet或routerLink)的组件上设置ROUTER_指令 @Component({ (...) template: ' <router-outlet></router-outlet> ', directives: [ ROUTER_DIRECTIVES ]

我想创建一个执行路由的服务。我想我需要路由器服务和路由器指令。我可以在我的服务中使用构造函数简单地注入路由器服务

如何添加路由器\u指令


Cheers

必须在使用相应指令(如ROUTER outlet或routerLink)的组件上设置ROUTER_指令

@Component({
  (...)
  template: '
    <router-outlet></router-outlet>
  ',
  directives: [ ROUTER_DIRECTIVES ]
})
(...)
@组件({
(...)
模板:'
',
指令:[路由器指令]
})
(...)
它们不适用于服务。只有路由器提供程序会这样做,因为您希望使用依赖项注入来注入相关的提供程序