i cant connect my localhost api . my environment.ts is:
export const environment = {
production: false,
apiUrl: 'http://127.0.0.1/slimapp/api/'
};
my httpservice:
post(serviceName: string, data: any) {
const headers = new HttpHeaders().set( 'Content-Type', 'application/json' );
const options = { headers: headers, withCredintials: false };
const url = environment.apiUrl + serviceName;
return this.http.post(url, JSON.stringify(data), options);
}
my login service is :
login(postData: any): Observable<any> {
return this.httpService.post('login', postData);
}
my connection where is my page.ts is:
this.authService.login(this.postData).subscribe(
(res: any) => {
if (res.userData) {
// Storing the User data.
this.storageService.store(AuthConstants.AUTH, res.userData);
this.storage.set('user_id', res.userData.id);
this.storage.set('name',res.userData.name);
this.router.navigate(['home/orders']);
} else {
this.alertService.presentAlert('','Yanlış Kullanıcı Adı ya da Şifre!');
}
},
(error: any) => {
this.alertService.presentAlert('',"Hata Oluştu");
this.toastService.presentToast(error.json())
}
);