Hi Hervé,

With the observables I find it very easy to use the async pipe: you don't 
have to subscribe, store the result, keep the subscription and unsubscribe 
when the component is destroyed.
I may have missed something but I use this extensively and I have not 
noticed any drawback yet.

Regards,
Arnaud.




On Friday, 25 October 2019 14:46:49 UTC+2, Hervé Le Cornec wrote:
>
> Hello,
>
> Many discussions here a related to the use of async data in Angular, so 
> let me recall the basics.
>
> Angular is natively designed to handle the async processes, because nearly 
> everthing is async in javascript (loading, events, ...). To intend so 
> Angular simply use the elvis operator "*?.*".
>
> Here is an example of a component that retrieve async data and displays it 
> :
>
> *1) The typescriptof the component *(a timeout has been setup to simulate 
> an async feed of the customer data)
> import { Component, OnInit } from '@angular/core';
>
> @Component({
>   selector: 'app-mycomponent',
>   templateUrl: './mycomponent.component.html',
>   styleUrls: ['./mycomponent.component.css']
> })
> export class MycomponentComponent implements OnInit {
>
>   customer: any;
>
>   constructor() { }
>
>   ngOnInit() {
>
>     //Feed the customer variable asynchronously
>     setTimeout(()=> {
>       this.customer = {
>         name: 'Bob',
>         age: 25
>       }
>     }, 2000);
>
>   }
> }
>
>
> *2) The HTML template of the component*
> <ul>
>   <li>Name : {{customer?.name}}</li>
>   <li>Age : {{customer?.age}}</li>
> </ul>
>
> This is as simple as this. 
> As you see there is no need for a "*| async*" in the template of the 
> component, there is neither any need for a direct use of rxjs observables.
>
> I hope this can help.
> Cheers
>
>
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to angular+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/angular/c3961620-8f50-4cde-b4e7-a7a4721f2c15%40googlegroups.com.

Reply via email to