2

I'm trying to evaluate an expression in ng-bind-html but it's not working. If anyone knows workaround for this, please help.

The code below is showing nothing.

<h5 ng-bind-html="{{feedType ==='popularProducts' ? displayedProduct.title : displayedProduct.name}}"></h5>
4
  • Are you getting any error in console and are you sure ng-bind-html will evaluate expression in {{}} ? I have tried in fiddle jsfiddle.net/L4zqv6fg/1 and {{}} itself is not getting evaluated.. Can you please update the fiddle with more info about controller details or why you are using ng-bind-html here? Commented Jan 1, 2020 at 8:38
  • {{}} is not working with ng-bind-html tag. That's why I'm asking for workaround. I'm using ng-bind-html because the content contains some symbol codes which is converted by html like registered/TM symbol code. Commented Jan 1, 2020 at 9:03
  • Got it. Can you please check stackoverflow.com/questions/40788937/… if this can help? Commented Jan 1, 2020 at 9:13
  • No I'm not supposed to add any kind of controller. All I can do is change in the tag with some angularjs directive. Commented Jan 1, 2020 at 9:24

1 Answer 1

3

The ngBindHtml directive expects the attribute value as an expression so there is no need for the {{}} interpolation. Simply remove those braces so that you’re passing your expression directly to the directive.

Working Syntax:

<h5 ng-bind-html="feedType === 'popularProducts' ? displayedProduct.title : displayedProduct.name"></h5>

Applicable AngularJS docs

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

Comments

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.