Angular 2: Inject a dependency into @CanActivate?

后端 未结 5 1193
心在旅途
心在旅途 2021-01-02 06:55

In Angular 2, you can specify a @CanActivate annotation for a component where you can determine if the component should be activated or not. The reason it\'s no

5条回答
  •  暖寄归人
    2021-01-02 07:23

    Here (https://gist.github.com/clemcke/c5902028a1b0934b03d9) is how to test the addInjector() solution that @shannon references:

    beforeEachProviders(()=>[PERSON_SERVICE_PROVIDERS]);
    
    beforeEach(inject([PersonService],()=>{
      let injector = Injector.resolveAndCreate([PERSON_SERVICE_PROVIDERS]);
      appInjector(injector);
    }));
    

提交回复
热议问题