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]/ItemService.prototype.getItems@http://localhost:4200/main.bundle.js:183:16
[108]/AppComponent.prototype.ngOnInit@http://localhost:4200/main.bundle.js:62:29
checkAndUpdateDirectiveInline@http://localhost:4200/vendor.bundle.js:11477:9
checkAndUpdateNodeInline@http://localhost:4200/vendor.bundle.js:12856:17
checkAndUpdateNode@http://localhost:4200/vendor.bundle.js:12824:16
debugCheckAndUpdateNode@http://localhost:4200/vendor.bundle.js:13453:38
debugCheckDirectivesFn@http://localhost:4200/vendor.bundle.js:13394:13
View_AppComponent_Host_0/<@ng:///AppModule/AppComponent_Host.ngfactory.js:8:5
debugUpdateDirectives@http://localhost:4200/vendor.bundle.js:13379:12
checkAndUpdateView@http://localhost:4200/vendor.bundle.js:12791:5
callWithDebugContext@http://localhost:4200/vendor.bundle.js:13779:39
debugCheckAndUpdateView@http://localhost:4200/vendor.bundle.js:13319:12
ViewRef_.prototype.detectChanges@http://localhost:4200/vendor.bundle.js:10888:54
ApplicationRef_.prototype.tick/<@http://localhost:4200/vendor.bundle.js:5818:58
ApplicationRef_.prototype.tick@http://localhost:4200/vendor.bundle.js:5818:13
ApplicationRef_.prototype._loadComponent@http://localhost:4200/vendor.bundle.js:5794:9
ApplicationRef_.prototype.bootstrap@http://localhost:4200/vendor.bundle.js:5782:9
PlatformRef_.prototype._moduleDoBootstrap/<@http://localhost:4200/vendor.bundle.js:5562:72
PlatformRef_.prototype._moduleDoBootstrap@http://localhost:4200/vendor.bundle.js:5562:13
PlatformRef_.prototype._bootstrapModuleFactoryWithZone/</</<@http://localhost:4200/vendor.bundle.js:5524:21
ZoneDelegate.prototype.invoke@http://localhost:4200/polyfills.bundle.js:2996:17
NgZone.prototype.forkInnerZoneWithAngularBehavior/this.inner<.onInvoke@http://localhost:4200/vendor.bundle.js:4891:28
ZoneDelegate.prototype.invoke@http://localhost:4200/polyfills.bundle.js:2995:17
Zone.prototype.run@http://localhost:4200/polyfills.bundle.js:2756:24
scheduleResolveOrReject/<@http://localhost:4200/polyfills.bundle.js:3391:52
ZoneDelegate.prototype.invokeTask@http://localhost:4200/polyfills.bundle.js:3029:17
NgZone.prototype.forkInnerZoneWithAngularBehavior/this.inner<.onInvokeTask@http://localhost:4200/vendor.bundle.js:4882:28
ZoneDelegate.prototype.invokeTask@http://localhost:4200/polyfills.bundle.js:3028:17
Zone.prototype.runTask@http://localhost:4200/polyfills.bundle.js:2796:28
drainMicroTaskQueue@http://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










©2024 concretepage.com | Privacy Policy | Contact Us