angular - 如何刷新 Angular MDB 轮播?
问题描述
我在我的应用程序中使用 Angular MDB Carousel ( https://mdbootstrap.com/docs/angular/ ) 来显示项目列表。添加新项目时,我希望刷新轮播。但是,在添加项目并且新项目与当前幻灯片重叠后会出现渲染问题。
我怎么解决这个问题?
这是我的代码:
我的组件.html:
<mdb-carousel [animation]="'slide'" [interval]="'0'" [isControls]="false" #carousel>
<mdb-carousel-item *ngFor="let item of (this.getItems() | async)">
<!-- ... -->
</mdb-carousel-item>
</mdb-carousel>
<a href="javascript:void(0)" (click)="onSlidePrevious()">
<mat-icon>keyboard_arrow_left</mat-icon>
</a>
<a href="javascript:void(0)" (click)="onSlideNext()">
<mat-icon>keyboard_arrow_right</mat-icon>
</a>
我的组件.ts:
export class MyComponent implements OnInit, OnDestroy {
@ViewChild('carousel') carousel: CarouselComponent;
constructor(
@Inject(MyService) public myService: MyService,
public dialog: MatDialog
) {
}
ngOnDestroy(): void {
}
ngOnInit(): void {
}
getItems() {
return this.myService.itemsChanged.asObservable();
}
onAddItem(newItem) {
const dialogConfig = new MatDialogConfig();
dialogConfig.height = '500px';
dialogConfig.autoFocus = false;
dialogConfig.data = JSON.parse(JSON.stringify(newItem));
const dialogRef = this.dialog.open(AddItemComponent, dialogConfig);
dialogRef.componentInstance.save.subscribe(
dataDialogForm => {
if (dataDialogForm !== undefined) {
let newItem= dataDialogForm;
this.myService.saveNewItem(newItem);
}
}
);
}
onSlidePrevious() {
this.carousel.previousSlide();
}
onSlideNext() {
this.carousel.nextSlide();
}
}
我的服务.ts:
export class MyService {
itemsChanged= new BehaviorSubject<>(this.data);
public saveNewItem(newItem) {
const data = this.itemsChanged.getValue();
data.unshift(newItem);
this.itemsChanged.next(data);
}
}
解决方案
推荐阅读
- optimization - 多个背包问题,同一类型的物品不能放在同一个背包中
- sql - 将 DMP 文件导入到 oracle 19 c
- reactjs - 我们如何更改反应材料 ui 表中标题的字体粗细?
- python - 在 javascript var 和 jscript 标签 Python BS4 中获取 json
- intellij-idea - build.gradle 无法识别 Closure
- visual-studio - 如何为 ToolStripDropDownButton 上的 MenuItem 创建事件处理程序?
- java - 在填充editText之前不会关闭弹出窗口的警报对话框按钮
- flutter - 在颤动文本字段中输入时变量被重置
- bash - 为标志查找文件(-i -d -p -a 等)
- swift - 新窗口总是以设定的大小打开