data binding - Dynamically set attribute on component in html template angular 2 -


i trying set attribute on component if expression true. give me example?

what have now:

 <div [danger]="inarray(choice.likers, user, id)"></div> 

but not compile.

inarray own method returns true or false. see is, if expression returns true, output be

<div danger></div> 

in angular 1 there this: ng-attr-... statement did above.

to set attribute use attribute binding:

 <div [attr.danger]="inarray(choice.likers, user, id)"></div> 

if want show empty attribute conditionally return empty string or null in inarray():

inarray() {     let value;     if (isinarray) {       value = '';     } else {       value = null;     }     return value;   } 

so attribute empty or danger attribute dont exist. result is:

<div danger></div> 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -