[英]Unexpected value 'BootstrapModalModule' imported by the module 'AppModule'
i am using webpack with angular2. 我正在使用angular2的webpack。 it fails while importing bootstrapmodalmodule from ng2-bootstrap-modal at runtime.
在运行时从ng2-bootstrap-modal导入bootstrapmodalmodule时失败。 Reference link is : ng2-bootstrap-modal
参考链接是: ng2-bootstrap-modal
And here's my files : 这是我的文件:
app.module.ts app.module.ts
import { NgModule } from '@angular/core';
import { CommonModule } from "@angular/common";
import { BrowserModule } from '@angular/platform-browser';
import { BootstrapModalModule } from 'ng2-bootstrap-modal';
import { ConfirmComponent } from './shared/login/confirm.component';
import { AppComponent } from './app.component';
@NgModule({
declarations: [ AppComponent, ConfirmComponent],
imports: [ CommonModule, BrowserModule, BootstrapModalModule ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
app.component.ts app.component.ts
import { Component } from '@angular/core';
import { ConfirmComponent } from './shared/login/confirm.component';
import { DialogService } from "ng2-bootstrap-modal";
@Component({
selector: 'pm-app',
templateUrl: './app.component.html'
})
export class AppComponent {
constructor(private dialogService:DialogService) {}
showConfirm() {
let disposable = this.dialogService.addDialog(ConfirmComponent, {
title:'Confirm title',
message:'Confirm message'})
.subscribe((isConfirmed)=>{
//We get dialog result
if(isConfirmed) {
alert('accepted');
}
else {
alert('declined');
}
});
//We can close dialog calling disposable.unsubscribe();
//If dialog was not closed manually close it by timeout
// setTimeout(()=>{
// disposable.unsubscribe();
// },10000);
}
}
confirm.component.ts confirm.component.ts
import { Component } from '@angular/core';
import { DialogComponent, DialogService } from "ng2-bootstrap-modal";
@Component({ selector: 'confirm',
template: `<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" (click)="close()" >×</button>
<h4 class="modal-title">{{title || 'Confirm'}}</h4>
</div>
<div class="modal-body">
<p>{{message || 'Are you sure?'}}</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" (click)="confirm()">OK</button>
<button type="button" class="btn btn-default" (click)="close()" >Cancel</button>
</div>
</div>`
})
export class ConfirmComponent extends DialogComponent {
constructor(dialogService: DialogService) {
super(dialogService);
}
confirm() {
// we set dialog result as true on click on confirm button,
// then we can get dialog result from caller code
this.result = true;
this.close();
}
}
Can you try to just import ModalModule from Ng2Bootstrap ? 您可以尝试从Ng2Bootstrap导入ModalModule吗?
ModalModule.forRoot(),
it's wokking form me 从我身上醒来
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.