Home  >  Forum  >  Angular
Post New Query

ERROR TypeError: this.http.get(...).toPromise is not a function



Asked on April 08, 2017
I am using angular 2 using Promise
    getItems(): Promise<Item[]> {
        return this.http.get(this.url).toPromise().then((res: Response) => res.json());
    }
But getting error

ERROR TypeError: this.http.get(...).toPromise is not a function
Stack trace:
[246]/[email protected]://localhost:4200/main.bundle.js:183:16
[108]/[email protected]://localhost:4200/main.bundle.js:62:29
[email protected]://localhost:4200/vendor.bundle.js:11477:9
[email protected]://localhost:4200/vendor.bundle.js:12856:17
[email protected]://localhost:4200/vendor.bundle.js:12824:16
[email protected]://localhost:4200/vendor.bundle.js:13453:38
[email protected]://localhost:4200/vendor.bundle.js:13394:13
View_AppComponent_Host_0/<@ng:///AppModule/AppComponent_Host.ngfactory.js:8:5
[email protected]://localhost:4200/vendor.bundle.js:13379:12
[email protected]://localhost:4200/vendor.bundle.js:12791:5
[email protected]://localhost:4200/vendor.bundle.js:13779:39
[email protected]://localhost:4200/vendor.bundle.js:13319:12
[email protected]://localhost:4200/vendor.bundle.js:10888:54
ApplicationRef_.prototype.tick/<@http://localhost:4200/vendor.bundle.js:5818:58
[email protected]://localhost:4200/vendor.bundle.js:5818:13
[email protected]://localhost:4200/vendor.bundle.js:5794:9
[email protected]://localhost:4200/vendor.bundle.js:5782:9
PlatformRef_.prototype._moduleDoBootstrap/<@http://localhost:4200/vendor.bundle.js:5562:72
[email protected]://localhost:4200/vendor.bundle.js:5562:13
PlatformRef_.prototype._bootstrapModuleFactoryWithZone/</</<@http://localhost:4200/vendor.bundle.js:5524:21
[email protected]://localhost:4200/polyfills.bundle.js:2996:17
NgZone.prototype.forkInnerZoneWithAngularBehavior/this.inner<[email protected]://localhost:4200/vendor.bundle.js:4891:28
[email protected]://localhost:4200/polyfills.bundle.js:2995:17
[email protected]://localhost:4200/polyfills.bundle.js:2756:24
scheduleResolveOrReject/<@http://localhost:4200/polyfills.bundle.js:3391:52
[email protected]://localhost:4200/polyfills.bundle.js:3029:17
NgZone.prototype.forkInnerZoneWithAngularBehavior/this.inner<[email protected]://localhost:4200/vendor.bundle.js:4882:28
[email protected]://localhost:4200/polyfills.bundle.js:3028:17
[email protected]://localhost:4200/polyfills.bundle.js:2796:28
[email protected]://localhost:4200/polyfills.bundle.js:3224:25



Replied on April 08, 2017
Use

import 'rxjs/add/operator/toPromise';



Replied on April 08, 2017
It is working. Thanks.

Write Answer







©2019 concretepage.com | Privacy Policy | Contact Us