My code is
import 'rxjs/Rx'; ... let _this = this; return new Promise(function(resolve, reject) { _this.http[method](url, data, { headers: headers }) .toPromise() .then( (data) => { resolve(data); }, error => { reject(error); } ); });
The "subscribe" not come from my code, looks like it's angular original something.
Error message:
EXCEPTION: Error: Uncaught (in promise): TypeError: _this.http.get(...).subscribe is not a function
let _this = this
if you use(resolve, reject) => {
instead. You don't neednew Promise(...)
when you usetoPromise()
. Justreturn this.http[method](url, data, { headers: headers }) .toPromise();
should do the same. – Günter Zöchbauer