Created
January 21, 2017 20:25
-
-
Save squadwuschel/9fbf480511c8275f620e656c4d82024a to your computer and use it in GitHub Desktop.
Implementieren unseres httpSubjectServices und die Subjects Subscriben
This file contains hidden or 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
import { Component } from '@angular/core'; | |
import { HttpSubjectService } from "../HttpInterception/httpSubject.service"; | |
import { Homeservice } from "../HttpServices/home.service"; | |
@Component({ | |
selector: 'app', | |
templateUrl: './app.component.html', | |
}) | |
export class AppComponent { | |
private locals: AppLocalsModel = new AppLocalsModel(); | |
constructor(private httpSubjectService : HttpSubjectService, private homeService : Homeservice) {} | |
ngOnInit(): void { | |
this.notifications(); | |
this.httpRedirects(); | |
this.spinner(); | |
this.overlay(); | |
} | |
public loadServiceData(): void { | |
this.homeService.getCurrentUsername() | |
.subscribe(result => { | |
this.locals.username = result; | |
}); | |
} | |
/** | |
* Wenn die Funktion für das Overlay angezeigt wird, dann soll dieses ausgeblendet werden | |
* da es z.B. zu einem Fehler gekommen ist im Request. | |
*/ | |
private overlay(): void { | |
this.httpSubjectService.overlaySubject.subscribe({ | |
next: () => { | |
console.log("Call Overlay Service"); | |
} | |
}); | |
} | |
/** | |
* Wir prüfen ob es noch offene Requests gibt und zeigen dies dann im Ui an. | |
*/ | |
private spinner(): void { | |
this.httpSubjectService.spinnerSubject.subscribe({ | |
next: (value: number) => { | |
console.log("Call Spinner Service"); | |
} | |
}); | |
} | |
/** | |
* Abfangen von Meldungen im aktuellen Response. Hier gibt es ein Property Message in dem | |
* Meldungen enthalten sind die dann im UI angezeigt werden können. | |
*/ | |
private notifications(): void { | |
this.httpSubjectService.notificationSubject.subscribe({ | |
next: (json: any) => { | |
console.log("Call Notification Service"); | |
} | |
}); | |
} | |
/** | |
* Wenn es beim Request zu einem Fehler kommt oder der User nicht Autorisiert ist, | |
* dann muss auf einen alternativen View verwiesen werden. | |
*/ | |
private httpRedirects(): void { | |
//Bei einem ServerFehler hier entsprechend den passendne View laden | |
this.httpSubjectService.http500Subject.subscribe({ | |
next: (error: any) => { | |
console.log("Navigate to Error Page"); | |
} | |
}); | |
//Wenn der User nicht autorisiert ist, hier auf den passenden View verweisen. | |
this.httpSubjectService.http403Subject.subscribe({ | |
next: (error: any) => { | |
console.log("Navigate to Not Authorized Page"); | |
} | |
}); | |
} | |
} | |
class AppLocalsModel { | |
public username : string = "noch nicht abgefragt"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment