admin管理员组文章数量:1426788
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
1 Answer
Reset to default 5Yes, 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.
本文标签: javascriptAngular ternary operator with html outputStack Overflow
版权声明:本文标题:javascript - Angular ternary operator with html output - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745486069a2660388.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论