0

in the tutorial angular2, there is two ways to use Promises: https://angular.io/docs/ts/latest/tutorial/toh-pt4.html

hero.service.ts

            import { Injectable } from '@angular/core';
            import { Hero } from './hero';
            import { HEROES } from './mock-heroes';
            @Injectable()
            export class HeroService {
                getHeroes() {
                    return Promise.resolve(HEROES);
                }

                getHeroesSlowly() {
                    return new Promise<Hero[]>(resolve =>
                        setTimeout(() => resolve(HEROES), 2000) // 2 seconds
                    );
                }
            }

why function HeroService() just call Promises object directly with Promise.resolve; from where come this object, it's ES6 ? but in the next function getHeroesSlowly() call a promises with new, why this difference?

1 Answer 1

1

Promise.resolve() is a static method (class level method) provided for common cases, and new Promise() just calls the constructor.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.