vendredi 20 janvier 2017

How to display an element if the optional field it is bind to is present in Angular2

I am trying to learn Angular2 with typescript and I'm having trouble on how to display an optional field on an interface.

I have something like:

export interface UserInfo {
   name:string;
   age:number;
   link?:string;
}

I am using ngFor on a custom div element that displays all those information using the normal notation. But i wanted to display an a tag only if there's a link property on the interface. I think it's an appropriate use optional fields on those interface, i just don't know how to use it in my template:

<a href="">Click me</a>

Do I have to use *ngIf? Or use evaluate an expression?




Aucun commentaire:

Enregistrer un commentaire