我刚接触Angular,并在尝试使用ng-bootstrap modal的简单示例时遇到了问题。我只是想打开一个窗口,但它却出现在我的应用程序中。我希望能像ng-bootstrap示例中所解释的那样打开一个新窗口。
我正在使用: - Angular 4.0.0 - Bootstrap 4.0.0-alpha.6 - @ng-bootstrap/ng-bootstrap 1.0.0-alpha.22
我在我的file.html文件中有以下内容:
我没有看到任何错误提示,只是在我的应用程序中打开了模态框,而不是一个新的窗口,我真的不明白为什么。
编辑: 这是我的问题截图: 问题截图 我有一个名为“启动演示模态框”的按钮,当我点击它时,“模态框标题”“一段很好的正文…”出现在按钮下方,而不是在模态框中。
我正在使用: - Angular 4.0.0 - Bootstrap 4.0.0-alpha.6 - @ng-bootstrap/ng-bootstrap 1.0.0-alpha.22
我在我的file.html文件中有以下内容:
<template #content let-c="close" let-d="dismiss">
<div class="modal-header">
<h4 class="modal-title">Modal title</h4>
<button type="button" class="close" aria-label="Close" (click)="d('Cross click')">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p>One fine body…</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" (click)="c('Close click')">Close</button>
</div>
</template>
<button class="btn btn-lg btn-outline-primary" (click)="open(content)">Launch demo modal</button>
<pre>{{closeResult}}</pre>
在我的 file.ts 文件中:
import { Component, Input, Output, EventEmitter, ViewContainerRef } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { NgbModal, NgbActiveModal, NgbModalOptions, NgbModalRef, ModalDismissReasons, NgbModalModule } from '@ng-bootstrap/ng-bootstrap';
@Component( {
selector: 'app-stagiaires',
templateUrl: './stagiaires.component.html',
styleUrls: ['./stagiaires.component.css'],
} )
export class StagiairesComponent {
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}`;
}
}
}
编辑: 这是我的问题截图: 问题截图 我有一个名为“启动演示模态框”的按钮,当我点击它时,“模态框标题”“一段很好的正文…”出现在按钮下方,而不是在模态框中。