Resolver Emitting Error ` ERROR Error: “[object Ob

2020-02-08 05:48发布

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

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

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();
          });

    });
  }

}

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

8条回答
我只想做你的唯一
2楼-- · 2020-02-08 06:19

one-time solution : find function defaultErrorLogger in dist/vendor.bundle.js and add:

for (var _i = 1; _i < arguments.length; _i++) {
    values[_i - 1] = arguments[_i];
}
console.log(arguments);
console.error.apply(console, values); code here

then refresh page without recompiling

查看更多
Animai°情兽
3楼-- · 2020-02-08 06:19

Mainly this error is found when using database object from '@angular/fire'

this can be fixed by using this.db.object('/' + ....).subscribe(...)

查看更多
登录 后发表回答