دنبال کننده ها

۱۳۹۶ اسفند ۲۸, دوشنبه

I want to call a api method from api class while my request is in other class in Angular or Ionic

[ad_1]



//User Service



import Injectable from '@angular/core';
import Api from './api/api';
@Injectable()
export class User {
static signIn(data) : Promise<User>

return new Promise((resolve, reject) =>
let seq = Api.post('login', JSON.stringify(email : 'ssss' , password:
'ssss'));
seq.subscribe((res: any) =>
// If the API returned a successful response, mark the user as logged in
if (res.status == 'success')
resolve(<User> res);
else

, err =>
alert('sssss')

);

return seq;
);




// Api Class code



import HttpClient, HttpParams from '@angular/common/http';
import Injectable from '@angular/core';
import 'rxjs/add/operator/map';
import Observable from 'rxjs/Observable';


/**
* Api is a generic REST Api handler. Set your API url first.
*/



@Injectable()
export class Api


url: string = 'http://localhost:8100/assets/data';



 constructor(public http: HttpClient) 




post(endpoint: string, body: any, reqOpts?: any)

return this.http.post(this.url + '/' + endpoint, body, reqOpts);





//please help me to resolve this issue




[ad_2]

لینک منبع