-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(modal): add modal service events, fix modal content onDestroy [f…
- Loading branch information
1 parent
8664bb1
commit c9f85e6
Showing
11 changed files
with
120 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,19 @@ | ||
import { Component } from '@angular/core'; | ||
import { Component, ViewChild } from '@angular/core'; | ||
import { ModalDirective } from 'ngx-bootstrap/modal/modal.component'; | ||
|
||
@Component({ | ||
selector: 'demo-modal-events', | ||
templateUrl: './events.html' | ||
}) | ||
export class DemoModalEventsComponent { | ||
@ViewChild(ModalDirective) public modal: ModalDirective; | ||
public messages: string[]; | ||
|
||
public showModal() { | ||
this.messages = []; | ||
this.modal.show(); | ||
} | ||
public handler(type: string, $event: ModalDirective) { | ||
console.log(`event ${type} is fired${$event.dismissReason ? ', dismissed by ' + $event.dismissReason : ''}`); | ||
this.messages.push(`event ${type} is fired${$event.dismissReason ? ', dismissed by ' + $event.dismissReason : ''}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
demo/src/app/components/+modal/demos/service-events/service-events.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<button type="button" class="btn btn-primary" (click)="openModal(template)">Open modal</button> | ||
<br><br> | ||
<pre *ngFor="let message of messages">{{message}}</pre> | ||
<template #template> | ||
<div class="modal-header"> | ||
<h4 class="modal-title pull-left">Modal</h4> | ||
<button type="button" class="close pull-right" aria-label="Close" (click)="modalRef.hide()"> | ||
<span aria-hidden="true">×</span> | ||
</button> | ||
</div> | ||
<div class="modal-body"> | ||
This is a modal | ||
</div> | ||
</template> |
41 changes: 41 additions & 0 deletions
41
demo/src/app/components/+modal/demos/service-events/service-events.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Component, TemplateRef } from '@angular/core'; | ||
import { BsModalService } from 'ngx-bootstrap/modal'; | ||
import { BsModalRef } from 'ngx-bootstrap/modal/modal-options.class'; | ||
import { Subscription } from 'rxjs/Subscription'; | ||
|
||
@Component({ | ||
selector: 'demo-modal-service-events', | ||
templateUrl: './service-events.html' | ||
}) | ||
export class DemoModalServiceEventsComponent { | ||
public modalRef: BsModalRef; | ||
public subscriptions: Subscription[] = []; | ||
public messages: string[] = []; | ||
constructor(private modalService: BsModalService) {} | ||
|
||
public openModal(template: TemplateRef<any>) { | ||
this.messages = []; | ||
this.subscriptions.push(this.modalService.onShow.subscribe((reason: string) => { | ||
this.messages.push(`onShow event has been fired`); | ||
})); | ||
this.subscriptions.push(this.modalService.onShown.subscribe((reason: string) => { | ||
this.messages.push(`onShown event has been fired`); | ||
})); | ||
this.subscriptions.push(this.modalService.onHide.subscribe((reason: string) => { | ||
this.messages.push(`onHide event has been fired${reason ? ', dismissed by ' + reason : ''}`); | ||
})); | ||
this.subscriptions.push(this.modalService.onHidden.subscribe((reason: string) => { | ||
this.messages.push(`onHidden event has been fired${reason ? ', dismissed by ' + reason : ''}`); | ||
this.unsubscribe(); | ||
})); | ||
this.modalRef = this.modalService.show(template); | ||
} | ||
|
||
|
||
public unsubscribe() { | ||
this.subscriptions.forEach((subscription: Subscription) => { | ||
subscription.unsubscribe(); | ||
}); | ||
this.subscriptions = []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters