2017-09-26 6 views
0

itemsAndPageableInfo 객체를 동적으로 생성 한 다음보기 itemsAndPageableInfo.content에서 인쇄하는 방법이 있습니까?서버에서 get() 후 동적으로 객체 생성

itemsAndPageableInfo : {};  

    this.itemService.getItems(0, 2) 
       .subscribe(res => { 
       this.itemsAndPageableInfo = res.json(); 
       this.items = res.json().content; 
       }); 

나는 <tr *ngFor="let item of itemsAndPageableInfo.content; let i = index">을하려고하지만 난 당신이로드 될 때까지 <tr>를 보여 빈 반복자에 itemsAndPageableInfo를 초기화 여부를 필요 ERROR TypeError: Cannot read property 'content' of undefined

+2

안전 연산자 사용 : ' –

답변

1

있다는 오류가 발생합니다.

itemsAndPageableInfo의 이유는 비동기 적으로 채워지고 요소가 DOM에로드 된 후 데이터가 표시되어 null 참조가 발생합니다.