change that to loginUserAll(data:any):Observable<any>
I am really confused…
login ts
this.loginUser.loginUserAll(datas).then(data => {
console.log(data.status);
console.log(data.data); // data received by server
console.log(data.headers);
})
.catch(error => {
console.log(error.status);
console.log(error.error); // error message as string
console.log(error.headers);
});
providers
import { Injectable } from '@angular/core';
import { HTTP } from '@ionic-native/http';
import { Platform } from 'ionic-angular';
import { fromPromise } from 'rxjs/observable/fromPromise';
@Injectable()
export class LoginUser {
data:any;
constructor(
private platform: Platform,
private nativeHttp: HTTP,
) { }
loginUserAll(data:any):Promise<any>{
this.platform.ready().then(() => {
return fromPromise(this.nativeHttp.post('http://btrc.urbanitsolution.com/api/login.php', data, {}))
});
}
}
fromPromise() converts a Promise to an Observable, you have to remove it from your provider.
Page:
this.loginUser.loginUserAll(datas).then(data => {
console.log(data.status);
console.log(data.data); // data received by server
console.log(data.headers);
})
.catch(error => {
console.log(error.status);
console.log(error.error); // error message as string
console.log(error.headers);
});
Provider:
import { Injectable } from '@angular/core';
import { HTTP } from '@ionic-native/http';
import { Platform } from 'ionic-angular';
import { fromPromise } from 'rxjs/observable/fromPromise';
@Injectable()
export class LoginUser {
data:any;
constructor(
private platform: Platform,
private nativeHttp: HTTP,
) { }
loginUserAll(data:any):Promise<any>{
return this.nativeHttp.post('http://btrc.urbanitsolution.com/api/login.php', data, {})
}
}
You also don’t need the platform.ready stuff since it’ll already be ready when it reaches that code. Copy and paste the code above.
This should work.
Thank you so much. without your help it was so tough to complete project. Thank you so much.
No problem
remember to set the post that helped you as the answer so other people can solve similar problems in future.
hi ismailcse11 please help me same error for me
There are many different issues discussed in this thread; perhaps you would get better results if you started a new topic for your problem.