Angular 1 - 将ng-if条件编译为字符串

时间:2017-11-13 10:04:30

标签: javascript angularjs angularjs-compile angularjs-interpolate

我有这个字符串:

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

解释我所做的{{notification}}表达式:

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

我现在要做的是在ng-if元素中添加span

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

$interpolate服务不支持此功能,如何“编译”ng-if的条件?

1 个答案:

答案 0 :(得分:0)

您可以使用本地scope

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