Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12141

Error NG2: Object is possibly 'undefined' when painting in the HTML Angular 17

$
0
0

I get this error when I put for example {{pokemon.name}} in the HTML and I get this NG2: Object is possibly 'undefined'.

  ngOnInit(): void {    this._route.params.subscribe(params =>{      this._apiService.getPokemon(params['name']).subscribe({        next: (res) => {          this.pokemon = {            name: res.name,            id: res.id,            sprites: res.sprites,            types: res.types          }          console.log('Pokemon: ', this.pokemon)        },        error: (err) => {          console.log(err);        }      })    })  }```the console printsPokemon:  {name: 'bulbasaur', id: 1, sprites: {…}, types: Array(2)}

Viewing all articles
Browse latest Browse all 12141

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>