December 2017
Beginner
372 pages
10h 32m
English
Now, we can use the _http object to make a web service call. We will create a function, getBoardsWithPromises where we will make a GET call to our JSON file and return the promise to the Homepage component.
The following is our code for the function:
getBoardsWithPromises(): Promise<Board[]> { if(this.Boards == undefined){ return this._http.get(this._boardUrl).toPromise() .then((response: Response) => { this.Boards = <Board[]>response.json(); return <Board[]> response.json() ; } ); } else { return Promise.resolve(this.Boards); } }
Let's go through each line of the function to understand the implementation:
Read now
Unlock full access