Nikhil Tambave
Nikhil Tambave

Reputation: 155

Angular 2.0 use new Promise() got error TypeError: promise_1.Promise is not a function

While use new Promise in angular 2.0 got error:

TypeError: promise_1.Promise is not a function

 var promise = new Promise(function (resolve, reject) {

        this.buildCSV();
           .then(accesstoken => {
           this.doClick();
       })
    });

Upvotes: 4

Views: 2730

Answers (1)

Thierry Templier
Thierry Templier

Reputation: 202156

You should try something like that:

var promise = new Promise((resolve, reject) => {          
    this.buildCSV();
});

promise.then(accesstoken => {
    this.doClick();
});

The then method should be used within the initialization callback of the promise.

Moreover don't forget to use arrow functions if you want to the this keyword in callbacks.

I don't see where you call the resolve / reject functions. The registered callbacks won't be called... What do you try to implement?

Regarding your error you could try to import this if the browser doesn't support promises out of the box (most of time this object is present):

<script src="../node_modules/es6-shim/es6-shim.js"></script>
<script src="../node_modules/es6-promise/es6-promise.js"></script>

In all cases, the Promise object can be used directly without any import... In your case the prefix promise_1 is à bit strange and names me think that you try to import it from something.

See this question for more details:

Upvotes: 1

Related Questions