Object 可以为 null。TS型

Object can be null. TS

提问人:DaroGawlik 提问时间:3/26/2023 最后编辑:Uwe KeimDaroGawlik 更新时间:3/26/2023 访问量:35

问:

(成分 | 异步)。成分 -> 对象可能是 'null'.ngtsc(2531)

我在哪里使用任何方法来传递此错误?

<a class="list-group-item" style="cursor: pointer;"
*ngFor="let ingredient of (ingredients | async).ingredients; let i = index" (click)="onEditItem(i)"> {{ ingredient.name}} ({{ ingredient.amount}}) </a>
export class ShoppingListComponent implements OnInit, OnDestroy {
  ingredients: Observable<{ ingredients: Ingredient[] }>;
  private inChnageSub: Subscription;

  constructor(
    private slService: ShoppingListService,
    private loggingService: LoggingService,
    private store: Store<{ shoppingList: { ingredients: Ingredient[] } }>
  ) {}

  ngOnInit(): void {
      this.ingredients = this.store.select('shoppingList');
  }
Angular TypeScript 对象 null

评论

3赞 MikeOne 3/26/2023
(成分|异步)?.成分应该解决它
0赞 Phalgun 3/26/2023
您遇到此问题的 Angular 版本是什么?

答: 暂无答案