-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implementación de modal-event mediante template * Se implementa modal-event mediante compoente modal
- Loading branch information
1 parent
09c2478
commit 46c6956
Showing
12 changed files
with
190 additions
and
1 deletion.
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
9 changes: 9 additions & 0 deletions
9
...onents/modal-events/components/modal-event-component/modal-event-component.component.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,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">×</span> | ||
</button> | ||
</div> | ||
<div class="modal-body"> | ||
This is a modal | ||
</div> |
Empty file.
25 changes: 25 additions & 0 deletions
25
...nts/modal-events/components/modal-event-component/modal-event-component.component.spec.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,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(); | ||
}); | ||
}); |
16 changes: 16 additions & 0 deletions
16
...mponents/modal-events/components/modal-event-component/modal-event-component.component.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,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(); | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
.../components/modal-events/components/modal-event-component/modal-event-component.module.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,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 {} |
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,3 @@ | ||
<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> |
Empty file.
25 changes: 25 additions & 0 deletions
25
src/app/components/modal-events/modal-events.component.spec.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,25 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { ModalEventsComponent } from './modal-events.component'; | ||
|
||
describe('ModalEventsComponent', () => { | ||
let component: ModalEventsComponent; | ||
let fixture: ComponentFixture<ModalEventsComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ ModalEventsComponent ] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(ModalEventsComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
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,70 @@ | ||
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', | ||
templateUrl: './modal-events.component.html', | ||
styleUrls: ['./modal-events.component.scss'] | ||
}) | ||
export class ModalEventsComponent { | ||
|
||
modalRef: BsModalRef; | ||
subscriptions: Subscription[] = []; | ||
messages: string[] = []; | ||
|
||
constructor( | ||
private modalService: BsModalService, | ||
private changeDetection: ChangeDetectorRef, | ||
) {} | ||
|
||
openModal() { | ||
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) => { | ||
const eventReason = reason ? `, dismissed by ${reason}` : ''; | ||
this.messages.push(`onHide event has been fired${eventReason}`); | ||
}) | ||
); | ||
|
||
this.subscriptions.push( | ||
this.modalService.onHidden.subscribe((reason: string) => { | ||
const eventReason = reason ? `, dismissed by ${reason}` : ''; | ||
this.messages.push(`onHidden event has been fired${eventReason}`); | ||
this.unsubscribe(); | ||
}) | ||
); | ||
|
||
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(ModalEventComponentComponent); | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
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: [ | ||
ModalEventsComponent, | ||
], | ||
imports: [ | ||
BrowserModule, | ||
ModalModule.forRoot(), | ||
ModalEventComponentModule, | ||
], | ||
exports: [ | ||
ModalEventsComponent, | ||
] | ||
}) | ||
export class ModalEventsModule { } |