1

I know there are other questions about this, but I already tryed and nothing seems to work.

I basically have an angular variable retrieved from an $http.get . The content is html encoded, like:

Paperwhite – Human Nature

So I have to display it as

<div ng-bind-html="songrel.title.rendered"></div>

To render the html:

Paperwhite – Human Nature

I want to split this value for the - and display only

Human Nature

I tryed something like

<div ng-bind-html="songrel.title.rendered.split('&#8211;')[1]"></div>

or

<div ng-bind-html="songrel.title.rendered.split('-')[1]"></div>

Or moving the code in my app.config

$scope.showFirstBr = function(content){
    return content.split('&#8211;')[1]
};

and then

<div ng-bind-html="showFirstBr(songrel.title.rendered)"></div>

but nothing seems to work. What am I missing?

2 Answers 2

1

Try this

var app = angular.module("MyApp", []).controller("MyCtrl", function($scope, $sce) {
  var str = 'Paperwhite &#8211; Human Nature';
  $scope.test = $sce.trustAsHtml(str.split('&#8211;')[1]);

})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="MyApp" ng-controller="MyCtrl">
  <div ng-bind-html="test"></div>
</body>

Sign up to request clarification or add additional context in comments.

1 Comment

I've fix with this $scope.showFirstBr = function(content){ var c = content.replace('&#8211;','-'); return c.split('-')[1] }; as an user wrote (he deleted the answer). My variable is the result of an $http.get that returns one or mutiple array. I have to access it inside an ng-repeat. Not sure how to use your code
0

I've fixed adding this in the controller:

$scope.showFirstBr = function(content){
    var c = content.replace('&#8211;','-');
    return c.split('-')[1]
};

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.