Nikhil Attar
Nikhil Attar

Reputation: 115

AngularJS ng-bind-html not working with expression

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>

Upvotes: 2

Views: 564

Answers (1)

g_param
g_param

Reputation: 156

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

Upvotes: 3

Related Questions