我正面臨一個我不清楚的錯誤。我能夠看到要編輯的數據,但每次都會出現這樣的錯誤。我試圖捕捉錯誤,但我沒有弄明白它來自哪里:每個 console.log 都像例外一樣工作。我認為問題在于第一次加載時的數據為空。這只有在我嘗試顯示第二個時才會出現,ngFor因為如果我只讓第一個而不是它工作正常但不顯示arrays of comments the second *ngFor.RROR TypeError: Cannot read property '1' of null at Object.eval [as updateDirectives] (PostsListComponent.html:20) at Object.debugUpdateDirectives [as updateDirectives]我正在獲取類似這樣的數據。<tr *ngFor="let post of posts$ | async; trackBy:trackByFunction"> <td class="title">{{post.title}}</td> <td class="dateTime">{{post.body}}</td> <div *ngFor="let comment of (groupedComments$ | async)[post.id]; trackBy:trackByFunction"> <div> <td *ngIf="!isEditable(comment)" class="comment">{{comment.name}}</td> <textarea class="comment" *ngIf="isEditable(comment)" [(ngModel)]="editableComment.name"></textarea> <td *ngIf="!isEditable(comment)"class="comment">{{comment?.body}}</td> <textarea class="comment" *ngIf="isEditable(comment)" [(ngModel)]="editableComment.body"></textarea> <td class="comment" *ngIf="comment.email === '[email protected]' && comment.body.length < 200"> {{comment.email}} <button *ngIf="!isEditable(comment)" (click)="deleteComment(comment.id)" class="btn btn-danger">Delete</button> <button *ngIf="!isEditable(comment)" (click)="editComment(comment)" class="btn btn-info" style="margin-left: 10px">Edit</button> <button *ngIf="isEditable(comment)" (click)="update(comment)" class="btn btn-info" style="margin-left: 10px">Update</button> <button *ngIf="isEditable(comment)" (click)="cancel()" class="btn btn-danger" style="margin-left: 10px">Cancel</button> </td> </div> </div> </tr>
無法在 Object.eval [as updateDirectives] 中讀取 null
慕娘9325324
2021-12-23 15:10:07