projects/app-base-library/src/lib/angular/services/modal.service.ts
Properties |
|
Methods |
constructor(bsModalService: BsModalService)
|
||||||
Parameters :
|
closeModal |
closeModal()
|
Returns :
void
|
openModalWithComponent | ||||
openModalWithComponent(options: )
|
||||
Parameters :
Returns :
void
|
parseOptions | ||||
parseOptions(options: )
|
||||
Parameters :
Returns :
void
|
Public bsModalRef |
bsModalRef:
|
Type : BsModalRef
|
Public bsModalService |
bsModalService:
|
Type : BsModalService
|
Private optionsDefault |
optionsDefault:
|
Type : object
|
Default value : {
data: {},
hasHeader: true,
hasFooter: true,
hasTitle: true,
fullScreen: false,
animated: true,
keyboard: true,
backdrop: true,
ignoreBackdropClick: false,
}
|
import { Injectable } from '@angular/core';
import { BsModalService } from 'ngx-bootstrap/modal';
// import { BsModalRef } from 'ngx-bootstrap/modal/modal-options.class';
import { BsModalRef } from 'ngx-bootstrap/modal';
@Injectable()
export class ModalService {
public bsModalRef: BsModalRef;
private optionsDefault = {
data: {},
hasHeader: true,
hasFooter: true,
hasTitle: true,
fullScreen: false,
animated: true,
keyboard: true,
backdrop: true,
ignoreBackdropClick: false,
};
constructor(public bsModalService: BsModalService) {
}
openModalWithComponent(options ) {
this.parseOptions(options);
this.bsModalRef = this.bsModalService.show(options.component , options );
this.bsModalRef.content.options = options ;
}
closeModal() {
this.bsModalRef.hide();
}
parseOptions(options) {
let defaults:any = JSON.parse(JSON.stringify(this.optionsDefault))
for (let k in defaults) {
if (typeof options[k] !== 'undefined') {
defaults[k] = options[k];
}
}
Object.assign(options, defaults)
}
}