简体   繁体   中英

Undefined is not an object(evaluating) - angular

I am passing data a from one component to another component in my application but i keep getting the error. I am trying to pass the object types from this.loggedInGames to advanced of play_game which is binding to an input in my html.

error

undefined is not object(evaluating this.loggedInGames.types) .

Below is my code

component

 constructor(){
     this.play_game.advanced = this.loggedInGames.types
     this.loggedInGames = JSON.parse(localStorage.getItem('loggedInGames'));
 }

 play_game = {
    advanced : "",
    amateur : ""                
 }

html

<input name="amateur" [(ngModel)]="play_game.advanced" />

Order should be changed, You are trying to access from a not initialized object.

 this.loggedInGames = JSON.parse(localStorage.getItem('loggedInGames'));
 this.play_game.advanced = this.loggedInGames.types;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM