{{ notification}}` to interpret the {{ notification}} expression I do : this.badge = thi" /> {{ notification}}` to interpret the {{ notification}} expression I do : this.badge = thi" /> {{ notification}}` to interpret the {{ notification}} expression I do : this.badge = thi"/>

Angular 1 - Compile ng-if condition into string

67 Views Asked by At

I have this string :

this.badge = `<span class="badge">{{ notification}}</span>`

to interpret the {{ notification}} expression I do :

this.badge = this.$interpolate(this.badge)(this)

What i would like to do now is to add an ng-if in the span element :

this.badge = `<span ng-if="notification > 0"class="badge">{{ notification}}</span>`

But the $interpolate service does not support this, how can I "compile" the condition of ng-if ?

1

There are 1 best solutions below

1
Dmitry Matrosov On

you can to use local scope:

this.badge = '<span ng-if="'+(scope.notification > 0)+'" class="badge">'+scope.notification+'</span>';