I would like to replace the "& ;" when it grabs the data from the database to "&".
So currently, it will display "Nursing & ; Doctor" rather then "Nursing & Doctor"
How can I achieve this using replace. I have tried ng-show, Santize, and ng-bind-html but have not worked out for me.
javascript
angularjs
Share
Improve this question
asked Sep 19, 2017 at 17:13
RobertRobert16711 gold badge22 silver badges1414 bronze badges
Add a ment
|
4 Answers
4
Reset to default
2
This is not necessarily the best way but for those of you that need to do this you can use this:
var parser = new DOMParser;
var dom = parser.parseFromString(YOURSTRING,'text/html');
var decodedString = dom.body.textContent;
You have to use $sce service and trustAsHtml so that Angular will not do the encoding and display the output without output encoding. Details are here https://docs.angularjs/api/ngSanitize
Steps are below-
Include ngSanitize module - angular.module('app', ['ngSanitize']);
Inject $sce service in your controller
Truest output using - vm.Specialty= $sce.trustAsHtml(Specialty);
Display to the user without output encoding - Specialty: bind-html-pile=e.Specialty