javascript - Angular ternary operator with html output - Stack Overflow

Is it possible to render the output from a ternary operator as html?{{ boolA ? 'Some text' :

Is it possible to render the output from a ternary operator as html?

{{ boolA ? 'Some text' : '<i class=\"fa fa-check\"></i>' }}

Also tried to modify a inline if/else directive from a previous question but can't get this to work either.

.filter('iif', ['$sce', function ($sce) {
    return function (input, trueValue, falseValue) {
        return $sce.trustAs('html', input ? trueValue : falseValue);
    }
}])

Is it possible to render the output from a ternary operator as html?

{{ boolA ? 'Some text' : '<i class=\"fa fa-check\"></i>' }}

Also tried to modify a inline if/else directive from a previous question but can't get this to work either.

.filter('iif', ['$sce', function ($sce) {
    return function (input, trueValue, falseValue) {
        return $sce.trustAs('html', input ? trueValue : falseValue);
    }
}])
Share Improve this question edited May 23, 2017 at 12:32 CommunityBot 11 silver badge asked Jul 19, 2016 at 9:05 stigstig 1,2406 gold badges26 silver badges45 bronze badges 3
  • Yes. it is possible to render. Have you written ng-bind-html in your html? – Varit J Patel Commented Jul 19, 2016 at 9:07
  • Which angular version are you using? – sabithpocker Commented Jul 19, 2016 at 9:12
  • why don't you do all this logic inside your controller ? – Rathma Commented Jul 19, 2016 at 9:43
Add a ment  | 

1 Answer 1

Reset to default 5

Yes, Use ng-bind-html like this :

<span ng-bind-html=" your_condition ? 'html_if_true' : 'html_if_false' "></span>

Replace values according to your requirements.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745486069a4629772.html

相关推荐

  • javascript - Angular ternary operator with html output - Stack Overflow

    Is it possible to render the output from a ternary operator as html?{{ boolA ? 'Some text' :

    1小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信