await functionality in angularjs 1.5

Viewed 3326

I am new to angularjs just 1.5 weeks of experience.

My service is returning IPromise. I am using that in controller as :

private GetHeader(): void {
        this._SolutionExplorerHeaderData = this.globalShellService.SolutionExplorerHeaderData;
        this.globalShellService.retrieveHeaderData().then(
            (response: Models.SolutionExplorerHeader) => {
                this._SolutionExplorerHeaderData = response;
            });
}

I am calling this method like this:

private InitComponents(): void {
        let statusBar = new LayoutModels.StatusBar(Designer.DesignerTitleKey);
        let designerShell = this.GetDesignerShell();
        let globalCommadBarHandler = this.globalCommandBarService;
        this.GetHeader();
        this.headerModel = new LayoutManager.Models.HeaderModel(this._SolutionExplorerHeaderData.SolutionType,
            this._SolutionExplorerHeaderData.Publisher,
            this._SolutionExplorerHeaderData.InstalledOn,
            this._SolutionExplorerHeaderData.ModifiedOn,
            this._SolutionExplorerHeaderData.LastSaved,
            this._SolutionExplorerHeaderData.LastPublished);
        this.layoutModel = new LayoutManager.Models.LayoutModel(Designer.DesignerName,
            designerShell, statusBar, globalCommadBarHandler, this.headerModel);
    }

Now the issue with this is .then() in GetHeader() will return the data a bit late before that header model mapping statement is called.

How should I await(C#) @this.GetHeader() statement so that execution pause at this statement.

1 Answers
Related