0

I'm doing an ng-repeat of an array with strings in it. The problem is some of the strings have special characters like "degrees" and fractional numbers. The output for the first item in the array below is "Oven 350&#176"....instead of "Oven 350*".

directions = [
				"Oven 350°",
				"Cook potatoes in boiling salted water until done",
				"The next day grate potatoes coarsely",
				"Mix with remaining ingredients",
				"Place in shallow 1.5 or 2 quart baking dish and bake about 35 minutes"
			];
<ul>
  <li ng-repeat="item in directions"></li>
</ul

1 Answer 1

3

In order to get the special characters to work you need to use ngBindHtml Documentation here

In order to use ngBindHtml you need to include angular-sanitize.min.js and include ngSanitize in your modules dependencies

Html

<div ng-controller="MyCtrl">
  <ul>
    <li ng-repeat="item in directions">
      <span ng-bind-html='item'></span>
    </li>
  </ul>
</div>

JavaScript

var app = angular.module('myApp', ['ngSanitize']);

function MyCtrl($scope) {
    $scope.directions = [
                "Oven 350&#176;",
                "Cook potatoes in boiling salted water until done",
                "The next day grate potatoes coarsely",
                "Mix with remaining ingredients",
                "Place in shallow 1.5 or 2 quart baking dish and bake about 35 minutes"
            ];
}

See the fiddle here

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.