Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/modal-events #3

Merged
merged 2 commits into from
Feb 9, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Se implementa modal-event mediante compoente modal
jreategui07 committed Feb 9, 2020
commit 5cef8ed2e53a3ed36e372429d1b7f402e2db901c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div class="modal-header">
<h4 class="modal-title pull-left">Modal</h4>
<button type="button" class="close pull-right" aria-label="Close" (click)="closeModal()">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
This is a modal
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { ModalEventComponentComponent } from './modal-event-component.component';

describe('ModalEventComponentComponent', () => {
let component: ModalEventComponentComponent;
let fixture: ComponentFixture<ModalEventComponentComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ModalEventComponentComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(ModalEventComponentComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Component } from '@angular/core';
import { BsModalRef } from 'ngx-bootstrap/modal';

@Component({
templateUrl: './modal-event-component.component.html',
styleUrls: ['./modal-event-component.component.scss']
})
export class ModalEventComponentComponent {

constructor(public bsModalRef: BsModalRef) { }

closeModal() {
this.bsModalRef.hide();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ModalEventComponentComponent } from './modal-event-component.component';
import { ModalModule } from 'ngx-bootstrap/modal';

@NgModule({
declarations: [
ModalEventComponentComponent
],
imports: [
BrowserModule,
ModalModule.forRoot(),
],
entryComponents: [
ModalEventComponentComponent
]
})
export class ModalEventComponentModule {}
13 changes: 1 addition & 12 deletions src/app/components/modal-events/modal-events.component.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
<button type="button" class="btn btn-primary" (click)="openModal(template)">Open modal</button>
<button type="button" class="btn btn-primary" (click)="openModal()">Open modal</button>
<br><br>
<pre class="card card-block card-header" *ngFor="let message of messages">{{message}}</pre>
<ng-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">&times;</span>
</button>
</div>
<div class="modal-body">
This is a modal
</div>
</ng-template>
27 changes: 15 additions & 12 deletions src/app/components/modal-events/modal-events.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Component, ChangeDetectorRef, TemplateRef } from '@angular/core';
import { Component, ChangeDetectorRef } from '@angular/core';
import { Subscription, combineLatest } from 'rxjs';
import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal';
import { ModalEventComponentComponent } from './components/modal-event-component/modal-event-component.component';

@Component({
selector: 'app-modal-events',
@@ -13,19 +14,14 @@ export class ModalEventsComponent {
subscriptions: Subscription[] = [];
messages: string[] = [];

constructor(private modalService: BsModalService, private changeDetection: ChangeDetectorRef) {
}
constructor(
private modalService: BsModalService,
private changeDetection: ChangeDetectorRef,
) {}

openModal(template: TemplateRef<any>) {
openModal() {
this.messages = [];

const combineEvents = combineLatest(
this.modalService.onShow,
this.modalService.onShown,
this.modalService.onHide,
this.modalService.onHidden
).subscribe(() => this.changeDetection.markForCheck());

this.subscriptions.push(
this.modalService.onShow.subscribe((reason: string) => {
this.messages.push(`onShow event has been fired`);
@@ -53,8 +49,15 @@ export class ModalEventsComponent {
})
);

const combineEvents = combineLatest(
this.modalService.onShow,
this.modalService.onShown,
this.modalService.onHide,
this.modalService.onHidden
).subscribe(() => this.changeDetection.markForCheck());
this.subscriptions.push(combineEvents);
this.modalRef = this.modalService.show(template);

this.modalRef = this.modalService.show(ModalEventComponentComponent);
}

unsubscribe() {
2 changes: 2 additions & 0 deletions src/app/components/modal-events/modal-events.module.ts
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ModalEventsComponent } from './modal-events.component';
import { ModalModule } from 'ngx-bootstrap/modal';
import { ModalEventComponentModule } from './components/modal-event-component/modal-event-component.module';

@NgModule({
declarations: [
@@ -10,6 +11,7 @@ import { ModalModule } from 'ngx-bootstrap/modal';
imports: [
BrowserModule,
ModalModule.forRoot(),
ModalEventComponentModule,
],
exports: [
ModalEventsComponent,