简体   繁体   English

未定义不是对象(评估)-角度

[英]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. 我正在将数据a从一个组件传递到应用程序中的另一个组件,但是我不断收到错误消息。 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. 我试图将对象类型从this.loggedInGames传递给play_game的高级对象,后者将绑定到我的html中的输入。

error 错误

undefined is not object(evaluating this.loggedInGames.types) . 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 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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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