ERROR错误 - 未捕获(承诺) - 错误 - 必须定义令牌

时间:2017-09-01 18:06:05

标签: angular angular2-routing angular2-forms

我正在为我的一条路线添加一个canDeactivate后卫。我创建服务,将其添加到Feature模块的提供者,并将其添加到路由本身。当我尝试访问路线时,我得到如下所示的异常。

现在的canDeactivate非常简单:

import { Injectable } from '@angular/core';
import {CanDeactivate, Router} from '@angular/router';
import { IrEditComponent } from'./index';


@Injectable()
export class ReferralGuardService implements CanDeactivate<IrEditComponent> {

  canDeactivate(component: IrEditComponent) { 
    return true;
  }
}

例外情况如下:

  

错误错误:未捕获(承诺):错误:必须定义令牌!   错误:必须定义令牌!在新的ReflectiveKey(core.es5.js:1405)   [有角度]在   KeyRegistry.webpackJsonp ... / .. / .. / core/@angular/core.es5.js.KeyRegistry.get   (core.es5.js:1452)[有角度] at   Function.webpackJsonp ... / .. / .. / core/@angular/core.es5.js.ReflectiveKey.get   (core.es5.js:1423)[有角度]       在ReflectiveInjector_.webpackJsonp ... / .. / .. / core/@angular/core.es5.js.ReflectiveInjector_.get   (core.es5.js:2489)[有角度的]       at resolveNgModuleDep(core.es5.js:9473)[angular]       在       NgModuleRef_.webpackJsonp ... / .. / .. / core/@angular/core.es5.js.NgModuleRef_.get   (core.es5.js:10555)[有角度的]       at resolveNgModuleDep(core.es5.js:9473)[angular]       在NgModuleRef_.webpackJsonp ... / .. / .. / core/@angular/core.es5.js.NgModuleRef_.get   (core.es5.js:10555)[有角度的]       在PreActivation.webpackJsonp ... / .. / .. / router / @angular / root.es5.js.PreActivation.getToken   (router.es5.js:4566)[棱角分明]       在PreActivation.webpackJsonp ... / .. / .. / router / @angular / root.es5.js.PreActivation.getResolver   (router.es5.js:4554)[有角度的]       在PreActivation.webpackJsonp ... / .. / .. / router / @angular / root.es5.js.PreActivation.resolveNode   (router.es5.js:4534)[有角度的]       在PreActivation.webpackJsonp ... / .. / .. / router / @angular / root.es5.js.PreActivation.runResolve   (router.es5.js:4515)[有角度的]       在MergeMapSubscriber.project(router.es5.js:4282)[有角度]       在MergeMapSubscriber.webpackJsonp ... / .. / .. / .. / rxjs / operator / mergeMap.js.MergeMapSubscriber._tryNext   (mergeMap.js:120)[有角度]       在新的ReflectiveKey(core.es5.js:1405)[有角度]

0 个答案:

没有答案