I have a problem with control flow in my method. How can I wait for data from the server?Is it possible to prepare data in constructor of service, and get it in singleton in all Components after inject?
import { Permission } from '../_models/Permission';
import { Injectable, OnInit } from "@angular/core";
import { AuthService, AppHttpService } from '../_services/index';
import { RequestActionType } from '../_models/RequestActionType';
@Injectable()
export class PermissionService {
private getUrl: string = "/Permission/GetAllPermissions";
private permissions: Permission[] = [];
constructor(private httpService: AppHttpService, private authService: AuthService) {
this.PreparePermissionData();
}
public PreparePermissionData() {
if (this.authService.loggedIn()) {
this.httpService.authGet(this.getUrl).then(response => {
this.permissions = response.Data as Permission[];
});
}