我想自定義與 UI 互動的組件。我已經更改了所有必要的檔案,但在我的新組件中,我混淆了如何匯入以便在打字稿中識別引導程式類。我只是從 javascript 遷移到 typescript,所以這就是發生的事情。
import { Component, OnInit } from '@angular/core';
import { bootstrapApplication } from '@angular/platform-browser';
@Component({
selector: 'app-modal',
templateUrl: './modal.component.html'
})
export class ModalComponent implements OnInit {
modal: any;
shown: false;
constructor() {
this.modal= new bootstrap.modal('#id', {
keyboard: true
});
this.shown= false;
}
ngOnInit(): void {
console.log('modal on init');
}
onClick(): void {
}
}
uj5u.com熱心網友回復:
以下是有關如何在您的應用程式中打開 ng-bootstrap 模式的一些快速指南:
- 通過運行添加
ng-bootstrap到您的角度應用程式ng add @ng-bootstrap/ng-bootstrap。 - 添加
NgbModalModule到您的app.module.ts. - 創建一個包含模態內容的新組件(通過運行
ng g c your/component/path/componentName - 通過將 ng-bootstrap 的模態服務注入建構式,將其傳遞到要打開模態的組件:
constructor(private modalService: NgbModal) {} - 在您的 onClick 函式中(或任何您想要實際打開模式的地方),包括以下代碼:
this.modalService.open(ComponentName);
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/535089.html
