0

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);
    }
}])
3
  • Yes. it is possible to render. Have you written ng-bind-html in your html? Commented Jul 19, 2016 at 9:07
  • Which angular version are you using? Commented Jul 19, 2016 at 9:12
  • why don't you do all this logic inside your controller ? Commented Jul 19, 2016 at 9:43

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Perfect, thanks. Then I can use angle brackets as well and just escape the quotes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.