How to see running errors in Angular 2+?

50 views Asked by At

I'm new to Angular 2+.
I'm playing a starter codebase Angular-Full-Stack, I found that I can't see any log/error printed.

For example, I modified some code in cats.component.ts:

import { Component, OnInit } from '@angular/core';
import { Logger } from "angular2-logger/core";    // added

import { CatService } from '../services/cat.service';
import { ToastComponent } from '../shared/toast/toast.component';
import { Cat } from '../shared/models/cat.model';

@Component({
  selector: 'app-cats',
  templateUrl: './cats.component.html',
  styleUrls: ['./cats.component.scss'],
  providers: [Logger]    // added
})
export class CatsComponent implements OnInit {

  cat = new Cat();
  cats: Cat[] = [];
  isLoading = true;
  isEditing = false;

  constructor(private catService: CatService,
    public toast: ToastComponent,
    private _logger: Logger,) { }

  ngOnInit(): void {
    this._logger.log('???')   // added
    console.error('???')   // added
    this.getCats();
  }

  getCats(): void {
    let a = 1 / 0    // added
    this._logger.log(a)    // added
    this.catService.getCats().subscribe(
      data => this.cats = data,
      error => console.log(error),
      () => this.isLoading = false
    );
  }

After these changes, the codebase still worked as usual. The problems are:
1, console.log/error doesn't work,
2, angular2-logger also doesn't work,
3, there is no error about "let a = 1 / 0", the related function works fine, it seems the compiler ignored this line,
4, I tried "throw" an error and it did stop the corresponding process, but also no error was shown.

Is there someone who can help understand these phenomena and give me some suggestion? Thank you.

0

There are 0 answers