解析器发出错误`ERROR错误:"[[对象对象]"" ` [英] Resolver Emitting Error ` ERROR Error: "[object Object]" `

查看:110
本文介绍了解析器发出错误`ERROR错误:"[[对象对象]"" `的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在路由上实现解析器时遇到问题,因为直到在路由模块中包含InitialDataResolver为止,它都没有问题.

I'm having a problem with regards of implementing a resolver on my routes as it has no issue until I include InitialDataResolver on my routing module.

pages-routing.module.ts

pages-routing.module.ts

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { FrontComponent } from '../layouts/front/front.component';
import { HomeComponent } from './home/home.component';
import { DocsComponent } from './docs/docs.component';
import { InitialDataResolver } from './../shared/resolvers/initial-data.resolver';

const routes: Routes = [
  {
    path: '',
    component: FrontComponent,
    children: [
      { path: '', component: HomeComponent },
      { path: 'docs', component: DocsComponent }
    ],
    resolve: {
      init: InitialDataResolver
    },
  }
];

@NgModule({
  imports: [ RouterModule.forChild(routes) ],
  exports: [ RouterModule ],
  providers: [ InitialDataResolver ]
})
export class PagesRoutingModule { }

initial-data.resolver.ts

initial-data.resolver.ts

import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, Resolve, RouterStateSnapshot } from '@angular/router';
import { Observer } from 'rxjs/Observer';
import { AppInitService } from '../services/app-init.service';
import { Observable } from 'rxjs/Observable';

@Injectable()
export class InitialDataResolver implements Resolve<any> {

  constructor(private appInitService: AppInitService) {}

  resolve(route: ActivatedRouteSnapshot,
          state: RouterStateSnapshot): Observable<any> {
    return Observable.create((observer: Observer<any>) => {

      this.appInitService.init()
          .subscribe(data => {
            this.appInitService.preload();
            observer.next(data);
            observer.complete();
          });

    });
  }

}

我遇到的错误是ERROR Error: "[object Object]".请参阅下面的快照:

The error that I'm encountering is ERROR Error: "[object Object]". see the snapshot below:

推荐答案

使用Mozilla Firefox时出现这种详细错误.因此,您需要做的是切换到Google Chrome来查看特定的错误.

This lack of detailed error occurred when using Mozilla Firefox. so what you need to do is to switch over to Google Chrome to see the specific error.

已更新:

您还可以将错误存储为全局变量

You can also Store the error as Global Variable

然后您可以键入temp0.message以查看实际的错误消息

then you can type temp0.message to see the actual error message

这篇关于解析器发出错误`ERROR错误:"[[对象对象]"" `的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆