I am new to Angular, to explain myself properly I will share an example.
When we have installed the Firebase library in our project, we can call the information in the Users table as follows:
constructor(db:AngularFirestore){
db.collection('Users').valueChanges().subscribe((data: User[]) => {
this.users= data;
console.log(this.users);
});
}
the valueChanges () method takes care of listening to any changes in the database and updating them in the user view without having to refresh it (this is done by making a manual change on a certain field in the same Firebase database).
So, in what way can this result be achieved, if for example I am consuming an API Rest? If by making a direct change in the database this change is reflected in the user's view without the need to refresh.
// users.service.ts
get():Observable<any>{
return this.httpClient.get(this.API_ENDPOINT+'/users_location');
}
// user.component.ts
users: Users[]=[];
constructor(private userService: UsersService) {
this.getTrailers();
}
getUsers(){
this.userService.get().subscribe( (data:Users[])=>{
this.users= data;
});
}