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.