paraBirims: ParaBirimi[];
Get_All(adres: any): Observable < T[] > {
return this.http.get < T[] > (this.base "/" adres);
}
getParaBirims(): ParaBirimi[] {
this.genericParaBirim?.Get_All("ParaBirimis/Generic_Method").subscribe({
next: (data) => {
this.paraBirims = data
},
error: (err) => {},
complete: () => {}
});
}
I want it to give me list as return in above code(getParaBirims). How should I write?
this.paraBirims = getParaBirims();
CodePudding user response:
Your getParaBirims() function should return a subscription, and you should consume that subscription by subscribing to it in your services and/or components or through the async pipe.
CodePudding user response:
I would recommend using the environment.ts file to define your URL prefixes. That way you can change them based on what environment you're running the app.
As dopoto said, it is better to simply define the Observable and subscribe to it in the component. We can remove a lot of boilerplate from your code and do the following.
public paraBirims$: Observable<ParaBirimi[]>;
constructor(private http:HttpClient){
this.paraBirims$ = this.http
.get<ParaBirimi[]>(`${environment.url}/ParaBirimis/Generic_Method`);
}
