【发布时间】:2018-08-21 00:34:54
【问题描述】:
我想使用 Angular 4.0.0 和 ng-bootstrap 1.0.0-beta.4 但它不显示模式。
应用模块.ts
@NgModule({
// ...
declarations: [
LoginComponent
],
imports: [
// ...
NgbModule.forRoot()
],
entryComponents: [LoginComponent],
})
export class AppModule { }
login.component.ts
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.css']
})
export class LoginComponent {
@ViewChild('examplemodal')
private modalRef: TemplateRef<any>;
constructor(private modalService: NgbModal) { }
//.... some event that fires onModalRequest()
onModalRequest(): void {
const modalRef = this.modalService.open(this.modalRef); //Not working
modalRef.result.then((result) => {
console.log(result);
console.log('closed');
}).catch( (result) => {
console.log(result);
console.log('cancelling');
});
}
}
examplemodal.html
<ng-template #examplemodal>
<div class="modal">
stuff here...
</div>
</ng-template>
有什么帮助吗?
【问题讨论】:
-
根据 API:内容可以作为 TemplateRef 或组件类型提供。你提供字符串.. 来源:ng-bootstrap.github.io/#/components/modal/api
-
你是对的!请检查我的编辑,我已经添加了一个 TemplateRef 但仍然无法正常工作。 @echonax
-
这个有错误吗?
-
@RafaelReyes - 您是否在项目中包含了 Bootstrap 4 CSS?我认为您使用的 ng-bootstrap 版本需要旧版本的 Bootstrap(类似于
4.0.0-beta.3)。 -
不,我使用的是 Bootstrap 3.3.7 @ConnorsFan
标签: angular modal-dialog ng-bootstrap