1 ) Make a different Service file where you can call rest APIs.
2) And make a call from your component by injection the services.
**For Example, Assume this is Service file assume ->**
getEvents(response) {
let accesstoken = localStorage.getItem('access_token');
let headers = new HttpHeaders();
headers = headers.append('Authorization', 'Bearer ' + accesstoken);
let url = this.baseUrl + 'getEventListingToAdmin?page=' + response.page + '&perPage=10';
var data = this.http.get(url, {headers: headers});
return data;
}
**And This is a Component Part -->**
first import the service file in component
import { AdminService } from '../../admin.service';
**Then Inject it in constructor**
constructor(private admin: AdminService) { }
ngOnInit () {
this.admin.getEvents(response)
.subscribe(
(data:any) => {
//USE CAN USE HERE LOADS
this.loading = false;
// CAN CHECK THE RESPONSE STATUS
if(data.statusCode==200){
this.managersData = data.data.EventData;
this.allItems = data.data.EventCount;
}
},
error => {
//USE CAN USE HERE LOADS
this.loading = false;
// CAN CHECK THE RESPONSE STATUS
if(error.error.statusCode===401)
{
// CAN ADD SWEET ALERT
Swal(
error.error.msg,
'error'
)
}
});
}