core/modal/modal.component.ts
C8y modal component.
Creating custom modal:
import { Component } from "@angular/core";
import { Subject } from 'rxjs';
@Component({
selector: "my-modal",
template: `
<c8y-modal title="CustomTitle"
(onClose)="onClose($event)"
(onDismiss)="onDismiss($event)"
[labels]="labels"
[disabled]="true" <- will disable ok button
>
<span>I am body of modal</span>
<span>For simple string use body="string"</span>
</c8y-modal>`
})
export class MyModalComponent {
closeSubject: Subject<boolean> = new Subject();
labels : ModalLabels = {ok: "customOK", cancel: "customCancel"};
onDismiss(event){
this.closeSubject.next(false);
}
onClose(event) {
this.closeSubject.next(true);
}
}
Showing modal:
import { BsModalService } from "ngx-bootstrap/modal";
constructor(
public bsModalService: BsModalService,
) {}
showModal() {
const modalRef = this.bsModalService.show(MyModalComponent);
modalRef.content.closeSubject.subscribe(result => {
console.log('results:', result);
});
}
selector | c8y-modal |
templateUrl | ./modal.component.html |
Methods |
Inputs |
Outputs |
HostListeners |
Accessors |
constructor(modal: BsModalRef)
|
||||||
Parameters :
|
body |
Type : string
|
close |
Type : function
|
customFooter |
Type : boolean
|
Default value : false
|
disabled |
Type : boolean
|
Default value : false
|
dismiss |
Type : function
|
headerClasses |
Type : string
|
Default value : ''
|
labels |
title |
Type : string
|
onClose |
Type : EventEmitter<boolean>
|
onDismiss |
Type : EventEmitter<boolean>
|
document:keydown.enter |
Arguments : '$event'
|
document:keydown.enter(event: KeyboardEvent)
|
_close |
_close()
|
Returns :
void
|
_dismiss |
_dismiss()
|
Returns :
void
|
onEnterKeyDown | ||||||
onEnterKeyDown(event: KeyboardEvent)
|
||||||
Decorators :
@HostListener('document:keydown.enter', ['$event'])
|
||||||
Parameters :
Returns :
void
|
labels | |||||
getlabels()
|
|||||
setlabels(undefined: ModalLabels)
|
|||||
Parameters :
Returns :
void
|
<div class="viewport-modal">
<div class="modal-header {{ headerClasses }}" [ngClass]="{ separator: title }">
<ng-content select="[c8y-modal-title]"></ng-content>
<h3 [hidden]="!title">
{{ title | translate }}
</h3>
</div>
<div class="modal-inner-scroll">
<div [ngClass]="{ 'modal-body': !customFooter, 'd-contents': customFooter }">
<p *ngIf="title" class="text-center text-break-word">
{{ body }}
</p>
<ng-content></ng-content>
</div>
</div>
<div class="modal-footer" *ngIf="!customFooter">
<ng-content select="[c8y-modal-footer]"></ng-content>
<button
title="{{ labels.cancel | translate }}"
*ngIf="labels.cancel"
class="btn btn-default"
(click)="_dismiss()"
>
{{ labels.cancel | translate }}
</button>
<button
title="{{ labels.ok | translate }}"
*ngIf="labels.ok"
class="btn btn-primary"
(click)="_close()"
[disabled]="disabled"
>
{{ labels.ok | translate }}
</button>
</div>
</div>