2

I'd like to use an AngularJS filter to search for a piece of text in a table and then use Angular-ui highlight to highlight the text.

I have the following code:

Search field:

<input type="text" ng-model="searchText"/>

Table with ng-repeat and angular-ui highlight

<table ng-repeat="fruit in fruits">
    <tr>
        <td>{{ fruit.name | highlight:searchText }}</td>
        <td>{{ fruit.price }}</td>
    </tr>
</table>

But my result looks like this:

Resulting HTML

I think I should be using ng-bind-html-unsafe, but am not sure of the correct way to implement it. Any ideas?

2 Answers 2

3

You can try

<span ng-bind-html-unsafe="fruit.name | highlight:searchText"></span>
Sign up to request clarification or add additional context in comments.

2 Comments

I tried that earlier (and included the angular sanitize module), but will try again.
@AndrewBoni If you use ng-bind-html, you need sanitize module, but if you the unsafe one you don't need that. (the unsafe one is not available in 1.2)
1

I have solved my issue, with help from user sza.

I am using AngularJS 1.2, and need to be using ng-bind-html not ng-bind-html-unsafe. The next step was to include the angular-sanitize.js script. The last step was to include in the directive ngSanitize to app.js.

Source and additional reading here

1 Comment

Thaaaanks!!!!!! This was it: "The last step was to include in the directive ngSanitize to app.js"

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.