angular 18 httpclient
Angular:-------
httpClient :library
APi methods:--Get,Post,Put,Delete.
apiitegration:--
getapi:component
:--
.ts:--
appconfig.ts:---
provider:[providerhttpClient]
get.api.components:--
userList:any[]=[];
import by two ways:--
http=inject(HttpClient);//injection
or
construct(private http:HttpClient){//dependency injection
}
getUser(){
subscribe to catch your data
debugger;
this.http.get(`url`).subscribe(result:any)=>{
this.userList=result;
}
}
Now call from html file:--
<button (click)=getUser()">click</button>
<select>
@for(item of userList;track $index){
<option>{item.name}</option>
</select>
services:---which can be used in no of component
that code u create in service.
ng g s department:--
service:--
in your ts file
edit and delete





Comments
Post a Comment