2017-02-19 9 views
1

私は最新の安定した角度2.4.4バージョンを使用します。トークンを定義する必要があります。新しいReflectiveKeyエラーで

サービスリゾルバを宣言してコンポーネントモジュールとルータに登録すると、何とか失敗します。この奇妙なエラーと

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…} 

可能な理由は何ですか?

答えて

2

同じ問題がありました。これはリゾルバサービスクラスの配置と関係があります。コンポーネントと同じフォルダに配置してみてください。私はそれを動作させています。

+0

ありがとうございます。同じタイスクリプトファイル内にリゾルバがありましたが、再利用されました。これはしばらくの間働いたが、突然すべての作業を中止した。私たちはリゾルバを自分のファイルに移動し、それを修正しました。私たちはまだ他のフォルダから使用していますが、この回答は間違いなく私たちを解決につなげました。 –

関連する問題