【发布时间】:2021-10-01 04:42:12
【问题描述】:
我创建了一个小的 tuto 代码,其中有一张卡片列表。在这些卡片上,我有一个点击事件,它传递了这些卡片的索引,稍后我将使用它来设置第一个图像以显示在轮播中。 该索引是通过与创建的组件共享的服务过去的。
目前该索引已成功通过,当我在轮播组件中收到它时,将其放入<ngb-carousel [activeId]="activeIndex">,如文档中所述
/**
* The slide id that should be displayed **initially**.
*
* For subsequent interactions use methods `select()`, `next()`, etc. and the `(slide)` output.
*/
activeId: string;
但是,我所做的没有任何效果,因为轮播仍然每次都向我显示第一张图片。我错过了什么吗?
这里可以找到源代码:https://github.com/agentjoseph007/modal-carousel
任何帮助将不胜感激。
【问题讨论】:
-
尝试在视图初始化生命周期设置活动索引
-
我尝试使用 view init 生命周期钩子,不幸的是它也没有字。
-
你需要为每个滑块赋予属性
[id]-是一个字符串-<ng-template ngbSlide [id]="one">..</ng-template>,然后你可以使用this.activeId="one"
标签: javascript angular bootstrap-4 angular-ui-bootstrap