错误:当前componentRef对于缓存的componentRef

时间:2017-07-01 09:41:24

标签: angular angular2-nativescript

我正在开发NativeScript Angular 2应用程序。

我有一个包含一堆对象的ListView。点击其中一个对象会打开一个新组件。按下后退按钮返回列表并按下列表中的另一个对象后,我收到以下错误:

我该如何解决这个问题?

CONSOLE ERROR file:///app/tns_modules/@angular/core/./bundles/core.umd.js:1091:24: ERROR Error: Uncaught (in promise): Error: Current componentRef is different for cached componentRef
    deactivate@file:///app/tns_modules/nativescript-angular/router/page-router-outlet.js:105:32 [angular]
    deactiveRouteAndOutlet@file:///app/tns_modules/@angular/router/./bundles/router.umd.js:4578:30 [angular]
    deactiveRouteAndItsChildren@file:///app/tns_modules/@angular/router/./bundles/router.umd.js:4538:40 [angular]
    deactivateRoutes@file:///app/tns_modules/@angular/router/./bundles/router.umd.js:4467:49 [angular]
    file:///app/tns_modules/@angular/router/./bundles/router.umd.js:4429:35 [angular]
    forEach@[native code] [angular]
    deactivateChildRoutes@file:///app/tns_modules/@angular/router/./bundles/router.umd.js:4428:36 [angular]
    activate@file:///app/tns_modules/@angular/router/./bundles/router.umd.js:4415:35 [angular]
    file:///app/tns_modules/@angular/router/./bundles/router.umd.js:4034:30 [angular]
    file:///app/tns_modules/rxjs/Observable.js:110:25 [angular]
    __tryOrSetError@file:///app/tns_modules/rxjs/Subscriber.js:247:20 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:187:42 [angular]
    _next@file:///app/tns_modules/rxjs/Subscriber.js:125:30 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    _next@file:///app/tns_modules/rxjs/operator/map.js:83:30 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    notifyNext@file:///app/tns_modules/rxjs/operator/mergeMap.js:143:34 [angular]
    _next@file:///app/tns_modules/rxjs/InnerSubscriber.js:23:31 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    _next@file:///app/tns_modules/rxjs/operator/map.js:83:30 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    _subscribe@file:///app/tns_modules/rxjs/observable/ScalarObservable.js:49:28 [angular]
    _trySubscribe@file:///app/tns_modules/rxjs/Observable.js:57:35 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:45:40 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:42:26 [angular]
    _innerSub@file:///app/tns_modules/rxjs/operator/mergeMap.js:130:55 [angular]
    _tryNext@file:///app/tns_modules/rxjs/operator/mergeMap.js:127:23 [angular]
    _next@file:///app/tns_modules/rxjs/operator/mergeMap.js:110:26 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    notifyNext@file:///app/tns_modules/rxjs/operator/mergeMap.js:143:34 [angular]
    _next@file:///app/tns_modules/rxjs/InnerSubscriber.js:23:31 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    _next@file:///app/tns_modules/rxjs/operator/map.js:83:30 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    _complete@file:///app/tns_modules/rxjs/operator/reduce.js:119:34 [angular]
    complete@file:///app/tns_modules/rxjs/Subscriber.js:114:27 [angular]
    _complete@file:///app/tns_modules/rxjs/operator/mergeMap.js:135:38 [angular]
    complete@file:///app/tns_modules/rxjs/Subscriber.js:114:27 [angular]
    _subscribe@file:///app/tns_modules/rxjs/observable/ArrayObservable.js:116:32 [angular]
    _trySubscribe@file:///app/tns_modules/rxjs/Observable.js:57:35 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:45:40 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:42:26 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:42:26 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:42:26 [angular]
    _innerSub@file:///app/tns_modules/rxjs/operator/mergeMap.js:130:55 [angular]
    _tryNext@file:///app/tns_modules/rxjs/operator/mergeMap.js:127:23 [angular]
    _next@file:///app/tns_modules/rxjs/operator/mergeMap.js:110:26 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    notifyNext@file:///app/tns_modules/rxjs/operator/mergeMap.js:143:34 [angular]
    _next@file:///app/tns_modules/rxjs/InnerSubscriber.js:23:31 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    _next@file:///app/tns_modules/rxjs/operator/map.js:83:30 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    notifyNext@file:///app/tns_modules/rxjs/operator/mergeMap.js:143:34 [angular]
    _next@file:///app/tns_modules/rxjs/InnerSubscriber.js:23:31 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    notifyComplete@file:///app/tns_modules/rxjs/operator/every.js:53:30 [angular]
    _complete@file:///app/tns_modules/rxjs/operator/every.js:70:28 [angular]
    complete@file:///app/tns_modules/rxjs/Subscriber.js:114:27 [angular]
    _complete@file:///app/tns_modules/rxjs/operator/mergeMap.js:135:38 [angular]
    complete@file:///app/tns_modules/rxjs/Subscriber.js:114:27 [angular]
    _subscribe@file:///app/tns_modules/rxjs/observable/ArrayObservable.js:116:32 [angular]
    _trySubscribe@file:///app/tns_modules/rxjs/Observable.js:57:35 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:45:40 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:42:26 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:42:26 [angular]
    _innerSub@file:///app/tns_modules/rxjs/operator/mergeMap.js:130:55 [angular]
    _tryNext@file:///app/tns_modules/rxjs/operator/mergeMap.js:127:23 [angular]
    _next@file:///app/tns_modules/rxjs/operator/mergeMap.js:110:26 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    notifyComplete@file:///app/tns_modules/rxjs/operator/every.js:53:30 [angular]
    _complete@file:///app/tns_modules/rxjs/operator/every.js:70:28 [angular]
    complete@file:///app/tns_modules/rxjs/Subscriber.js:114:27 [angular]
    _complete@file:///app/tns_modules/rxjs/operator/mergeMap.js:135:38 [angular]
    complete@file:///app/tns_modules/rxjs/Subscriber.js:114:27 [angular]
    _subscribe@file:///app/tns_modules/rxjs/observable/ArrayObservable.js:116:32 [angular]
    _trySubscribe@file:///app/tns_modules/rxjs/Observable.js:57:35 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:45:40 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:42:26 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:42:26 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:42:26 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:42:26 [angular]
    _innerSub@file:///app/tns_modules/rxjs/operator/mergeMap.js:130:55 [angular]
    _tryNext@file:///app/tns_modules/rxjs/operator/mergeMap.js:127:23 [angular]
    _next@file:///app/tns_modules/rxjs/operator/mergeMap.js:110:26 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    _next@file:///app/tns_modules/rxjs/operator/map.js:83:30 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    notifyNext@file:///app/tns_modules/rxjs/operator/mergeMap.js:143:34 [angular]
    _next@file:///app/tns_modules/rxjs/InnerSubscriber.js:23:31 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    _next@file:///app/tns_modules/rxjs/operator/map.js:83:30 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    _subscribe@file:///app/tns_modules/rxjs/observable/ScalarObservable.js:49:28 [angular]
    _trySubscribe@file:///app/tns_modules/rxjs/Observable.js:57:35 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:45:40 [angular]
    subscribe@file:///app/tns_modules/rxjs/Observable.js:42:26 [angular]
    _innerSub@file:///app/tns_modules/rxjs/operator/mergeMap.js:130:55 [angular]
    _tryNext@file:///app/tns_modules/rxjs/operator/mergeMap.js:127:23 [angular]
    _next@file:///app/tns_modules/rxjs/operator/mergeMap.js:110:26 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    notifyNext@file:///app/tns_modules/rxjs/operator/mergeMap.js:143:34 [angular]
    _next@file:///app/tns_modules/rxjs/InnerSubscriber.js:23:31 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    _next@file:///app/tns_modules/rxjs/operator/map.js:83:30 [angular]
    next@file:///app/tns_modules/rxjs/Subscriber.js:89:23 [angular]
    _subscribe@file:///app/tns_modules/rxjs/observable/ScalarObservable.js:49:28 [angular]

```

2 个答案:

答案 0 :(得分:2)

我遇到了这个错误,因为详细信息页面引用了操作栏中的对象属性...(看起来它在操作栏被渲染时没有实例化)希望它有所帮助

答案 1 :(得分:0)

我刚在我的属性中添加了一个* ngIf来验证它是不是未定义的。

示例:

<StackLayout *ngIf="example">
    <Label textWrap="true" [text]="example.title"></Label>
    <Image [src]="example.image" height="100"></Image>
</StackLayout>