我正在尝试在 Modal 中使用最基本的折叠功能,但折叠不会触发
从字面上看,只是将这个 w3schools 折叠示例复制到我的模态中。
这是我的模态代码:
<template #content let-c="close" let-d="dismiss" ngbModalContainer>
<div class="modal-header">
<h4 class="modal-title">Collapse</h4>
</div>
<form>
<div class="modal-body">
<button type="button" class="btn btn-info" data-toggle="collapse" data-target="#demo">Simple collapsible</button>
<div id="demo" class="collapse">
This is the collapsible text!
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" (click)="c('Close click')">Close</button>
</div>
</form>
</template>
<button class="btn btn-success" (click)="open(content)">Open Modal</button>
我的基本模态组件:
@Component({
selector: 'basic-modal',
templateUrl: './BasicModal.html'
})
export class BasicModalComponent {
closeResult: string;
constructor(private modalService: NgbModal) {}
open(content) {
this.modalService.open(content).result.then((result) => {
this.closeResult = `Closed with: ${result}`;
}, (reason) => {
this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
});
}
private getDismissReason(reason: any): string {
if (reason === ModalDismissReasons.ESC) {
return 'by pressing ESC';
} else if (reason === ModalDismissReasons.BACKDROP_CLICK) {
return 'by clicking on a backdrop';
} else {
return `with: ${reason}`;
}
}
}
我的应用组件:
@Component({
selector: 'my-app',
template: '<basic-modal></basic-modal>'
})
export class AppComponent { }
我的应用模块:
@NgModule({
imports: [NgbModule, FormsModule],
declarations: [AppComponent, BasicModalComponent],
bootstrap: [AppComponent],
})
export class AppModule {
}
我尝试调试 DOM 中折叠的行为,好像当你折叠<div>
它时它会添加一些类和一些属性,而当它折叠回来时它也会改变它们。
当我在 Modal 中调试它时,触发折叠按钮不会操纵 DOM,其类<div>
及其属性保持不变。
有任何想法吗?