[Fixed] Can I set condition to component selector Angular 2/4

Issue

Is it possible to add condition for a compnente selector ?

For exmple if I have a 2 simple compnenets :

First:

@Component({
             selector:'app-first'
             templateHtml: 'first.html;
            })
export class FirstComponent {
   check=false;
}

Second:

 @Component({
              selector:'app-second'
              templateHtml: 'second.html;
           })

Then ,on my first.html file I set this condition:

<div *ngIf="check">
 <app-second></app-second>
</div>

It’s always load me any way the second component,can I avoid this ? and
why it’s happens?I don’t find anything about that issue.

Thank you.

Solution

Yes it works, you can even do

<app-second *ngIf="check"></app-second>

Do you have any errors in your console ? because this should work perfectly.

Leave a Reply

(*) Required, Your email will not be published