Search code examples
angularjsng-html2js

Angular ng-bind-html-unsafe expression


Hi I'm using angular and I want to do an expression in my ng-bind-html-unsafe so that it can choose between two text to show. Is this the right syntax for the expression?

<div  ng-bind-html-unsafe="{{ 0 && text || text2}}"></div>

Here's a jsfiddle that show my problem.


Solution

  • Try without braces:

      <div  ng-bind-html-unsafe=" 0 && text || text2"></div>
    

    Output:

    HELLO THERE2
    

    for

    <div  ng-bind-html-unsafe=" 1 && text || text2"></div>
    

    Output

     HELLO THERE
    

    Fiddle

    As a side note, ng-bind-html-unsafe is removed from newer versions. In the future it can lead to errors