import { Component,OnInit, ViewContainerRef } from '@angular/core'; import {Profile} from '../../models/profile.model'; import {ProfileService} from '../../services/profiles.service'; import {MdDialog, MdDialogRef,MdDialogConfig} from '@angular/material'; import {YesNoDialog} from '../../dialogs/yes-no.dialog'; import {Subscription} from 'rxjs/Subscription'; @Component({ selector: 'profile-overview', templateUrl:'app/profiles/profile-overview/profile-overview.component.html' }) export class ProfileOverviewComponent implements OnInit{ private title: string; private profiles:Profile[] = []; private deleteDialogRef: MdDialogRef; private profileSubscription:Subscription; constructor(private profileService:ProfileService, public dialog: MdDialog, public viewContainerRef: ViewContainerRef,) { } ngOnInit(){ this.title="Profile overview" this.loadProfiles(); } private loadProfiles(){ if(this.profileSubscription){ this.profileSubscription.unsubscribe(); } this.profileSubscription = this.profileService.getProfiles().subscribe( (data)=>{ this.profiles=data; } ); } delete($event:any, username:string){ let config = new MdDialogConfig(); this.deleteDialogRef = this.dialog.open(YesNoDialog, config); this.deleteDialogRef.componentInstance.dialogContent="Weet u zeker dat u dit profile wenst te verwijderen?"; this.deleteDialogRef.afterClosed().subscribe(result => { this.deleteDialogRef = null; }); this.deleteDialogRef.afterClosed().subscribe(result => { if(result=="yes"){ this.profileService.deleteProfile(username).subscribe((){ this.loadProfiles() }); } this.deleteDialogRef= null; }); } }