您好,登錄后才能下訂單哦!
在Angular中使用自定義Bootstrap模態窗口可以通過以下步驟實現:
npm install bootstrap
angular.json
文件中添加以下配置:"styles": [
"node_modules/bootstrap/dist/css/bootstrap.min.css",
"src/styles.css"
],
"scripts": [
"node_modules/bootstrap/dist/js/bootstrap.min.js"
]
ng generate component modal
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="myModalLabel">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
Your modal content goes here...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
import { Component } from '@angular/core';
declare var $: any;
@Component({
selector: 'app-modal',
templateUrl: './modal.component.html',
styleUrls: ['./modal.component.css']
})
export class ModalComponent {
openModal() {
$('#myModal').modal('show');
}
closeModal() {
$('#myModal').modal('hide');
}
}
import { Component } from '@angular/core';
import { ModalComponent } from './modal/modal.component';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
constructor(private modalComponent: ModalComponent) {}
openCustomModal() {
this.modalComponent.openModal();
}
}
這樣就可以在Angular項目中使用自定義的Bootstrap模態窗口代替原生或第三方庫的彈窗功能了。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。