Thank you Herve,

I'm new to angular so i'm leaning something everyday :D. Just one question 
though. Since the "customer" variable may not be set when the view is 
rendered so the {{}} is the mechanism that angular is asynchonously watch 
the var and render when the value is available? If it is then why or when 
should we use async pipe?

Thai

On Friday, October 25, 2019 at 3:18:15 AM UTC-4, Hervé Le Cornec wrote:
>
> Here is your component, with a timeout to setup the customer in order to 
> simulate an async process :
> 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() {
>
>     setTimeout(()=> {
>       this.customer = {
>         name: 'Bob',
>         age: 25
>       }
>     }, 1000);
>
>   }
> }
>
> And here is the HTML template of the component :
> <p>
>   mycomponent works!
> </p>
> <ul>
>   <li>name : {{customer?.name}}</li>
>   <li>Age : {{customer?.age}}</li>
> </ul>
>
>
> Try to delete the ? of the elvis operator in the template : you get an 
> error message.
>
> This is all what you need. Isn't it great ?!
>
> 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/5809e1d2-7113-435a-95c4-3f6d728f12d9%40googlegroups.com.

Reply via email to