Is there a way to wait before the service initializes to load other components? I need to load some data synchronously before displaying the components (which require the data), and I don't want to use promises/observables (using those for async calls)
ngIf doesn't seem to cut it (component loads even though if doesn't match).
I'm not using router (don't need it for the app), so I don't think @CanActivate is suitable in this case.
Any ideas?
@Component({
selector: 'my-app',
directives: [MyDirective],
template: `
<div>
<div *ngIf="!initialized">Loading...</div>
<div *ngIf="initialized"><myDirective>should wait for service to be initialized</myDirective></div>
</div>`
})
export class AppComponent {
initialized = false;
constructor(_myService: MyService) {
this._myService = _myService;
}
ngOnInit() {
this._myService.init()
.then(() => {
setTimeout( () => this.initialized = true, 2000);
}
);
}
}