TypeError: Converting circular structure to JSON when trying to POST request

前端 未结 6 1018
星月不相逢
星月不相逢 2021-02-12 15:34

I am getting the error in the title and here is the full stack trace, i am not sure what it is, any insight is welcomed!

browser_adapter.js:84 EXCEPTION: Error i         


        
6条回答
  •  温柔的废话
    2021-02-12 16:31

    That's probably because of circular dependency in the object. In that case, it's not possible to stringify but it's always possible to log to browser console. So we can create a very basic pipe for this purpose.

    in app.module.ts:

    import { LogPipe } from './log.pipe';
    
    @NgModule({
      declarations: [
        //...
        LogPipe,
      ],
    })
    export class AppModule {}
    
    @Pipe({name: 'log'})
    export class LogPipe implements PipeTransform {
        public transform(value: object): void {
            console.log(value);
            return;
        }
    }
    

    Then we can use the pipe for fast logging

    {{'some text' | log}}
    

提交回复
热议问题