I am using SB-Admin-BS4-Angular-4-master theme in angular4. Theme has link to https://v4-alpha.getbootstrap.com/ I want to use bootstrap modals in my code. I used modals as per documentation in the theme.
For the same i used
import { NgbModal, ModalDismissReasons } from '@ng-bootstrap/ng-bootstrap';
in app.module.ts
Then i had to install ng-bootstrap via npm as it was not working.
import {NgbModule} from '@ng-bootstrap/ng-bootstrap';
When i installed ngbootstrap, webpack was being removed..
Cannot find module 'webpack/lib/node/NodeTemplatePlugin'
I installed webpack again as per Error: Cannot find module 'webpack/lib/node/NodeTemplatePlugin'
Now i am getting error this error when i open that module where i have used modal code..
Error: Uncaught (in promise): Error: No provider for NgbModalStack!
injectionError@http://localhost:4200/vendor.bundle.js:58005:90
noProviderError@http://localhost:4200/vendor.bundle.js:58043:12
../../../core/@angular/core.es5.js/</ReflectiveInjector_.prototype._throwOrNull@http://localhost:4200/vendor.bundle.js:59485:19
../../../core/@angular/core.es5.js/</ReflectiveInjector_.prototype._getByKeyDefault@http://localhost:4200/vendor.bundle.js:59524:20
../../../core/@angular/core.es5.js/</ReflectiveInjector_.prototype._getByKey@http://localhost:4200/vendor.bundle.js:59456:20
../../../core/@angular/core.es5.js/</ReflectiveInjector_.prototype.get@http://localhost:4200/vendor.bundle.js:59325:16
resolveNgModuleDep@http://localhost:4200/vendor.bundle.js:66317:12
_createClass@http://localhost:4200/vendor.bundle.js:66363:113
_createProviderInstance$1@http://localhost:4200/vendor.bundle.js:66328:26
resolveNgModuleDep@http://localhost:4200/vendor.bundle.js:66313:17
../../../core/@angular/core.es5.js/</N…
Stack trace:
resolvePromise@http://localhost:4200/polyfills.bundle.js:6634:31
resolvePromise@http://localhost:4200/polyfills.bundle.js:6605:17
scheduleResolveOrReject/<@http://localhost:4200/polyfills.bundle.js:6683:17
../../../../zone.js/dist/zone.js/</</ZoneDelegate.prototype.invokeTask@http://localhost:4200/polyfills.bundle.js:6264:17
onInvokeTask@http://localhost:4200/vendor.bundle.js:60717:24
../../../../zone.js/dist/zone.js/</</ZoneDelegate.prototype.invokeTask@http://localhost:4200/polyfills.bundle.js:6263:17
../../../../zone.js/dist/zone.js/</</Zone.prototype.runTask@http://localhost:4200/polyfills.bundle.js:6031:28
drainMicroTaskQueue@http://localhost:4200/polyfills.bundle.js:6441:25
../../../../zone.js/dist/zone.js/</</ZoneTask.invokeTask@http://localhost:4200/polyfills.bundle.js:6342:21
invokeTask@http://localhost:4200/polyfills.bundle.js:7266:9
globalZoneAwareCallback@http://localhost:4200/polyfills.bundle.js:7284:17
core.es5.js:1020
Do i need to install ng-bootstrap if i am already using a bootstrap theme to use bootstrap components?
HTML code
<div class="tableinfowrap">
<div class="card-header">
<div class="row">
<div class="col-xl-10"><h3>Tables</h3></div>
<div class="col-xl-2"> <a class="btn btn-primary" [routerLink]="['addresttable']" role="button">Add Table</a> </div>
</div>
</div>
<table class="card-block table table-hover">
<thead>
<tr>
<th>Table Number</th>
<th>Sitting Capacity</th>
<th>QR Code Url</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody *ngFor="let table of tablelist" >
<tr>
<td>{{table.tableNumber}}</td>
<td>{{table.seatingCapacity}}</td>
<td>{{table.qrCodeUrl}}</td>
<td ><i class="fa fa-fw fa-edit"></i></td>
<td (click)="open(content)"><i class="fa fa-fw fa-trash"></i></td>
</tr>
</tbody>
</table>
<ng-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>
</ng-template>
</div>
.ts file code
import { Component, OnInit } from '@angular/core';
import { Router, RouterModule} from '@angular/router';
import { routerTransition } from '../../router.animations';
import { plainToClass } from 'class-transformer';
import { classToPlain } from 'class-transformer';
import {FormsModule} from '@angular/forms';
import {TablesbyResId, ResTablesData} from '../../model/TablesbyResId';
import {TablebyResIdService} from '../../services/TablebyResIdService.service';
import { NgbModule, NgbModal, ModalDismissReasons } from '@ng-bootstrap/ng-bootstrap';
@Component({
selector: 'app-tableinfo',
templateUrl: './tableinfo.component.html',
styleUrls: ['./tableinfo.component.scss'],
providers: [TablebyResIdService ,NgbModal]
})
export class TableinfoComponent implements OnInit {
tablelist: ResTablesData[];
deletemodal = false;
message: boolean;
closeResult: string;
constructor(public router: Router, public tablebyresidservice: TablebyResIdService, private modalService: NgbModal) { }
ngOnInit()
{
this.tablebyresidservice.getTablebyIdApi()
.subscribe(
res =>
{
const tableResponse = plainToClass(TablesbyResId, res as Object)
console.log(tableResponse);
if (res.error === true){
alert(res.message);
console.log(res.message);
console.log(res.statusCode);
console.log(res.error);
/* this.router.navigate(['/login']); */
}
else
{
console.log("api hit success");
this.tablelist = tableResponse.data;
}
},
error => {this.tablebyresidservice.throwError(error);},
() => {}
);
}
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}`;
}
}
}