• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

如何调试未被捕获(在promise中):EmptyError:由router.navigate引起的序列中没有元素?

angular 来源:Iancovici 6次浏览

我想实现生成列表中的一些成分简单的角度路线如何调试未被捕获(在promise中):EmptyError:由router.navigate引起的序列中没有元素?

const appRoutes: Routes = [ 
    { path: ''  ,redirectTo: '/recipes', pathMatch: 'full'}, 
    { path: 'recipes'    , component: RecipesComponent}, 
    { path: 'recipes/:recipeName' , component: RecipesComponent}, 
]; 

,我有一个 更新点击状态变量和路径的功能,虽然我也有提取机制,用户发生在初始化。

ngOnInit() { 
    this.route.params 
     .subscribe(
     (params: {Params}) => { 

      this.selectedRecipe = this.findRecipeByName(params['recipeName']); 
     }); 
    } 


    navRecipe(recipeName: string): void { 
     let path = '/recipes/' + recipeName; 
     this.selectedRecipe = this.findRecipeByName(recipeName); 
     this.router.navigate([path]); 
    } 

但是,当我尝试单击重新路由到组件与参数,我得到以下的链接:

core.js:1350 ERROR Error: Uncaught (in promise): EmptyError: no elements in sequence 
EmptyError: no elements in sequence 
    at new EmptyError (EmptyError.js:28) 
    at FirstSubscriber._complete (first.js:154) 
    at FirstSubscriber.Subscriber.complete (Subscriber.js:122) 
    at MergeMapSubscriber._complete (mergeMap.js:150) 
    at MergeMapSubscriber.Subscriber.complete (Subscriber.js:122) 
    at MapSubscriber.Subscriber._complete (Subscriber.js:140) 
    at MapSubscriber.Subscriber.complete (Subscriber.js:122) 
    at EmptyObservable._subscribe (EmptyObservable.js:83) 
    at EmptyObservable.Observable._trySubscribe (Observable.js:172) 
    at EmptyObservable.Observable.subscribe (Observable.js:160) 
    at new EmptyError (EmptyError.js:28) 
    at FirstSubscriber._complete (first.js:154) 
    at FirstSubscriber.Subscriber.complete (Subscriber.js:122) 
    at MergeMapSubscriber._complete (mergeMap.js:150) 
    at MergeMapSubscriber.Subscriber.complete (Subscriber.js:122) 
    at MapSubscriber.Subscriber._complete (Subscriber.js:140) 
    at MapSubscriber.Subscriber.complete (Subscriber.js:122) 
    at EmptyObservable._subscribe (EmptyObservable.js:83) 
    at EmptyObservable.Observable._trySubscribe (Observable.js:172) 
    at EmptyObservable.Observable.subscribe (Observable.js:160) 
    at resolvePromise (zone.js:824) 
    at resolvePromise (zone.js:795) 
    at eval (zone.js:873) 
    at ZoneDelegate.invokeTask (zone.js:425) 
    at Object.onInvokeTask (core.js:4621) 
    at ZoneDelegate.invokeTask (zone.js:424) 
    at Zone.runTask (zone.js:192) 
    at drainMicroTaskQueue (zone.js:602) 
    at ZoneTask.invokeTask [as invoke] (zone.js:503) 
    at invokeTask (zone.js:1540) 

===========解决方案如下:

我遇到了与Angular v 4.4.6相同的错误。我发现有两种解决方案可以解决这个错误。一个是将pathMatch: 'full'添加到每个路由定义。另一个是将rxjs降低到v5.5.3以下。如果一个人不适合你,也许另一个人会。

更新:它出现的问题已被固定在rxjs v5.5.5。在使用Angular 5.0.5的项目中,将rxjs升级到v5.5.5后,错误停止发生。


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)