Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 - apply ngIf on host element using @HostBinding

Tags:

angular

I'm trying to set ngIf on the host element using @HostBinding decorator.

class ListItem {
    @HostBinding('ngIf') active: boolean = false;
}

And I'm getting the error: Can't bind to 'ngIf' since it isn't a known property of 'list-item'.

However I see an answer here which seems to be suggesting this usage.

like image 304
parliament Avatar asked Oct 23 '16 18:10

parliament


1 Answers

ngIf is a directive and directives can't be added dynamically. They are only applied if markup added statically to a components template matches the selector.

@HostBinding() only supports class., attr., and style. bindings.

like image 138
Günter Zöchbauer Avatar answered Nov 20 '22 21:11

Günter Zöchbauer