Search code examples
javascriptknockout.jsspecial-characters

Special characters in bound knockout data model


I have a data model with special characters in it (degree signs).. so the property contains the following: "48 ° f". However, when the UI updates to this data, I see the "°", not the degree sign. I have also tried "°", but that doesn't work either.

How do I put special characters in the data model and have them appear on the UI?


Solution

  • You should use html binding for this:

    <span data-bind="html: test"></span>
    
    var vm = {
        test: ko.observable("48 &deg; f")
    };
    
    ko.applyBindings(vm);
    

    Here is a working fiddle: http://jsfiddle.net/svu82/

    Read more in the KO documentation: http://knockoutjs.com/documentation/html-binding.html