3

I have a text with special characters and want to print title text out in Ionic 2 Framework.

<ion-card-title>
   {{ title }}
</ion-card-title>

Current string:

Expert Q&#038;A

Expected result:

Expert Q&A

However, the result keeps the same version which is

Expert Q&#038;A

I tried to use unescape(), but it still doesn't work. Any ideas? Thanks,

georgeawg
  • 48,608
  • 13
  • 72
  • 95
Dale Nguyen
  • 1,930
  • 3
  • 24
  • 37

2 Answers2

1

You can use [innerHTML] like this:

<ion-card-title [innerHTML]="title">
</ion-card-title>
Tomislav Stankovic
  • 3,080
  • 17
  • 35
  • 42
0

You'll have to use Strict Contextual Escaping (SCE) like this:

$scope.ampersand = $sce.trustAsHtml('&#038');
$scope.title = "Expert Q" + ampersand + "A";

Alternatively you could put this into a filter.

Randy Casburn
  • 13,840
  • 1
  • 16
  • 31
  • Thanks, Randy. The string is prepopulated. It's not something that I can concat like that or I should use str.substring() to get it then combine it again. It still not practical in this case. – Dale Nguyen Feb 26 '18 at 16:59
  • OK. The issue isn't splitting the string so much as it is placing it into an expression (or binding). It looks like it would be messy or impractical as you say. If it is impractical (probably due to variations), it seems the correct solution would be to get something from the source that you can use without modification. I'm assuming the source is a server? Transform it on the server doable? – Randy Casburn Feb 26 '18 at 17:18
  • 1
    @Dale - Tomislav has the answer - I upvoted him - go with it! – Randy Casburn Feb 26 '18 at 17:28