【问题标题】:Can we use ngx-lightbox with async pipe?我们可以将 ngx-lightbox 与异步管道一起使用吗?
【发布时间】:2020-11-27 03:36:01
【问题描述】:

在我重写我的组件之前,我想问问这是否真的有必要。

在official documentation 中,他们正在构建一个包含三个属性(src、标题、tumb)的“专辑”对象

显然,“open”方法期望如此。

如前所述,我没有在组件中订阅我的 API 的 observable,我只是将它传递给异步管道:

course$: Observable<Course>;
this.course$ = this.courseService.getSingle(this.courseId);

(...)

<ng-container *ngIf="course$ | async as course; else loading">

我的意思是文档一切正常。我可以只订阅组件并构建那个专辑数组......但是,在这样做之前,我想知道是否有办法保留我当前的解决方案。

课程$:可观察的;还包含一个对象数组,但看起来不同:

export interface Course {
  id: number
  images?: Image[];
}

export interface Image {
  id: number;
  imageURL: string;
  description: string;
}

我的目标是构建文档中描述的内容(简单部分)

<div *ngFor="let image of course.images; let i=index">
  <img [src]="image.imageURL" (click)="open(i)" />
</div>

棘手的部分可能是“打开”事件侦听器,它将访问他们在组件的构造函数中构建的所述“专辑”数组...

【问题讨论】:

    标签: angular lightbox


    【解决方案1】:

    好的,我自己回答。我订阅了组件中的 observable 并构建了该数组。似乎是唯一的方法。

    【讨论】:

      猜你喜欢
      • 2018-11-01
      • 1970-01-01
      • 2018-06-01
      • 1970-01-01
      • 2012-04-25
      • 2022-01-04
      • 2012-07-13
      • 1970-01-01
      • 2021-06-02
      相关资源
      最近更新 更多