Commit 409cb122 authored by avovchuk's avatar avovchuk

fix demo app

parent 8ac3d533
......@@ -22,7 +22,7 @@
"@angular/platform-browser-dynamic": "^2.4.3",
"@angular/router": "^3.3.1",
"core-js": "^2.4.1",
"ng2-bootstrap-modal": "git+https://github.com/ankosoftware/ng2-bootstrap-modal.git",
"ng2-bootstrap-modal": "^0.0.1",
"rxjs": "^5.0.1",
"ts-helpers": "^1.1.1",
"zone.js": "^0.7.2"
......
/* tslint:disable:no-unused-variable */
import { TestBed, async } from '@angular/core/testing';
import { AppModule } from './app.module';
import { AppComponent } from './app.component';
describe('AppComponent', () => {
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [
AppComponent
imports: [
AppModule
],
});
TestBed.compileComponents();
......@@ -19,16 +20,20 @@ describe('AppComponent', () => {
expect(app).toBeTruthy();
}));
it(`should have as title 'app works!'`, async(() => {
it('should render button "Show confirm"', async(() => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app.title).toEqual('app works!');
fixture.detectChanges();
const compiled = fixture.debugElement.nativeElement;
expect(compiled.querySelector('button').textContent).toContain('Show confirm');
}));
it('should render title in a h1 tag', async(() => {
//FIXME:Uncaught Error: Error in ./AppComponent class AppComponent - inline template:3:10 caused by: Cannot read property 'hostView' of undefined
/*it('should render confirm dialog by click', async(() => {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
const compiled = fixture.debugElement.nativeElement;
expect(compiled.querySelector('h1').textContent).toContain('app works!');
}));
compiled.querySelector('button').click();
expect(compiled.querySelector('.modal')).toBeDefined();
}));*/
});
import { Component } from '@angular/core';
import { ConfirmComponent } from './confirm.component';
import { DialogService } from "ng2-bootstrap-modal";
import Timer = NodeJS.Timer;
@Component({
selector: 'app',
template: `
<div class="container">
<button class="btn btn-default" (click)=showConfirm()>Show confirm</button>
<div class="container" >
<h1>ng2-bootstrap-modal demo application</h1>
<button class="btn btn-default" (click)=showConfirm()>Show confirm</button>
<span>Result: <b>{{ confirmResult }}</b></span>
</div>
`
})
export class AppComponent {
confirmResult:boolean = null;
timeoutId:Timer;
constructor(private dialogService:DialogService) {}
showConfirm() {
let disposable = this.dialogService.addDialog(ConfirmComponent, {
......@@ -18,17 +23,20 @@ export class AppComponent {
message:'Confirm message'})
.subscribe((isConfirmed)=>{
//We get dialog result
if(isConfirmed) {
alert('accepted');
}
else {
alert('declined');
}
this.confirmResult = !!isConfirmed;
});
//We can close dialog calling disposable.unsubscribe();
if(this.timeoutId) {
clearTimeout(this.timeoutId);
}
//If dialog was not closed manually close it by timeout
setTimeout(()=>{
this.timeoutId = setTimeout(()=>{
disposable.unsubscribe();
this.confirmResult = null;
},10000);
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment