September 2017
Intermediate to advanced
450 pages
11h 24m
English
Promises are simply an abstraction for handling callback functions in asynchronous code, that are easier to read. We declare the result of our service call getPosts as a promise to return BlogPost's array . By calling Promise.resolve, we are returning the Promise object in its asynchronously incomplete state:
getPromiseObject(): Promise<Model[]> { return Promise.resolve(ASYNC_MODEL_SOURCE);}
When the source of this promise's data is resolved, we will receive a callback through the then method in our component:
this.service.getPromiseObject().then(object => {/* use object */});
The ES6 arrow function (or fat-arrow), wraps the scope of our promise result so that we can act on it in the same scope of our component that we originally ...
Read now
Unlock full access