![](/img/trans.png)
[英]Why I get TypeError: undefined is not an object (evaluating '') in Angular?
[英]Undefined is not an object(evaluating) - angular
我正在將數據a從一個組件傳遞到應用程序中的另一個組件,但是我不斷收到錯誤消息。 我試圖將對象類型從this.loggedInGames傳遞給play_game的高級對象,后者將綁定到我的html中的輸入。
錯誤
undefined is not object(evaluating this.loggedInGames.types)
。
下面是我的代碼
零件
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" />
順序應更改,您正在嘗試從未初始化的對象訪問。
this.loggedInGames = JSON.parse(localStorage.getItem('loggedInGames'));
this.play_game.advanced = this.loggedInGames.types;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.