必须定义令牌!在新的ReflectiveKey错误

时间:2017-02-19 20:08:38

标签: angular typescript

我使用最新稳定的Angular 2.4.4版本。

不知何故,当我声明服务解析器并在组件模块和路由器中注册它时,它会失败。

import { Injectable } from '@angular/core';
import { Resolve, ActivatedRouteSnapshot } from '@angular/router';
import { Observable } from 'rxjs/Rx';
import { PGService, PG} from '../pg/';

@Injectable()
export class HomeServiceResolver implements Resolve<any> {
    constructor(
        private pgService: PGService
    ) { }

    resolve(route: ActivatedRouteSnapshot): Observable<PG> {
        return Observable.from([new PG()]);
    }
}

有这个奇怪的错误

vendor.dll.js:73630 Error: Uncaught (in promise): Error: Token must be defined!
Error: Token must be defined!
    at new ReflectiveKey (vendor.dll.js:54947) [angular]
    at KeyRegistry.get (vendor.dll.js:55000) [angular]
    at Function.ReflectiveKey.get (vendor.dll.js:54965) [angular]
    at ReflectiveInjector_.get (vendor.dll.js:100258) [angular]
    at MyAppModuleInjector.NgModuleInjector.get (vendor.dll.js:74217) [angular]
    at PreActivation.getToken (vendor.dll.js:25710) [angular]
    at :9000/vendor.dll.js:25697:51 [angular]
    at :9000/vendor.dll.js:9128:86 [angular]
    at forEach (vendor.dll.js:9106) [angular]
    at waitForMap (vendor.dll.js:9126) [angular]
    at PreActivation.resolveNode (vendor.dll.js:25696) [angular]
    at PreActivation.runResolve (vendor.dll.js:25683) [angular]
    at MergeMapSubscriber.project (vendor.dll.js:25499) [angular]
    at MergeMapSubscriber._tryNext (vendor.dll.js:17439) [angular]
    at resolvePromise (zone.js:501) [angular]
    at resolvePromise (zone.js:486) [angular]
    at :9000/polyfills.bundle.js:3838:17 [angular]
    at Object.onInvokeTask (vendor.dll.js:42772) [angular]
    at ZoneDelegate.webpackJsonp../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:274) [angular]
    at Zone.webpackJsonp../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:151) [<root> => angular]
    at drainMicroTaskQueue (zone.js:433) [<root>]
    at XMLHttpRequest.ZoneTask.invoke (zone.js:349) [<root>]
    ErrorHandler.handleError @ vendor.dll.js:73630
    next @ vendor.dll.js:53364
    schedulerFn @ vendor.dll.js:55453
    SafeSubscriber.__tryOrUnsub @ vendor.dll.js:588
    SafeSubscriber.next @ vendor.dll.js:537
    Subscriber._next @ vendor.dll.js:490
    Subscriber.next @ vendor.dll.js:454
    Subject.next @ vendor.dll.js:4491
    EventEmitter.emit @ vendor.dll.js:55439
    NgZone.triggerError @ vendor.dll.js:42841
    onHandleError @ vendor.dll.js:42802
    webpackJsonp../node_modules/zone.js/dist/zone.js.ZoneDelegate.handleError @ zone.js:246
    webpackJsonp../node_modules/zone.js/dist/zone.js.Zone.runGuarded @ zone.js:129
    _loop_1 @ zone.js:444
    drainMicroTaskQueue @ zone.js:453
    ZoneTask.invoke @ zone.js:349
    zone.js:420 Unhandled Promise rejection: Token must be defined! ; Zone: angular ; Task: Promise.then ; Value: ZoneAwareError {__zone_symbol__error: Error: Token must be defined!
    at new ReflectiveKey (http://localhost:9000/vendor.dll.js:54947:19…, __zone_symbol__stack: "Error: Token must be defined!↵    at new Reflectiv…/localhost:9000/vendor.dll.js:17439:27) [angular]", __zone_symbol__message: "Token must be defined!"} Error: Token must be defined!
    at new ReflectiveKey (http://localhost:9000/vendor.dll.js:54947:19) [angular]
    at KeyRegistry.get (http://localhost:9000/vendor.dll.js:55000:39) [angular]
    at Function.ReflectiveKey.get (http://localhost:9000/vendor.dll.js:54965:35) [angular]
    at ReflectiveInjector_.get (http://localhost:9000/vendor.dll.js:100258:94) [angular]
    at MyAppModuleInjector.NgModuleInjector.get (http://localhost:9000/vendor.dll.js:74217:52) [angular]
    at PreActivation.getToken (http://localhost:9000/vendor.dll.js:25710:25) [angular]
    at http://localhost:9000/vendor.dll.js:25697:51 [angular]
    at http://localhost:9000/vendor.dll.js:9128:86 [angular]
    at forEach (http://localhost:9000/vendor.dll.js:9106:13) [angular]
    at waitForMap (http://localhost:9000/vendor.dll.js:9126:5) [angular]
    at PreActivation.resolveNode (http://localhost:9000/vendor.dll.js:25696:101) [angular]
    at PreActivation.runResolve (http://localhost:9000/vendor.dll.js:25683:81) [angular]
    at MergeMapSubscriber.project (http://localhost:9000/vendor.dll.js:25499:30) [angular]
    at MergeMapSubscriber._tryNext (http://localhost:9000/vendor.dll.js:17439:27) [angular]
    consoleError @ zone.js:420
    _loop_1 @ zone.js:449
    drainMicroTaskQueue @ zone.js:453
    ZoneTask.invoke @ zone.js:349
    zone.js:422 ZoneAwareError {__zone_symbol__error: Error: Uncaught (in promise): Error: Token must be defined!
    Error: Token must be defined!
        at new…, rejection: ZoneAwareError, promise: ZoneAwarePromise, zone: Zone, task: ZoneTask…}

可能的原因是什么?

1 个答案:

答案 0 :(得分:2)

有同样的问题。它与解析程序服务类的位置有关。尝试将其放在与组件相同的文件夹中,并且我已将其工作。