kazou
kazou

Reputation: 77

Angularjs 2 JSON Unicode Characters

I retrieve a JSON file like this:

[
    {
    "title": {
        "renderer": "Etupes rate l’occasion de ramener le nul",
    },
    "title": {
        "renderer": "T Z J à RIOZ – Mathilde et Nicolas sur le podium",

    },...
    ]

I'm parsing that within ionic 2 app:

public newsObj = [];

ionViewWillEnter () {
     console.log("getNews");

     this.getNews().subscribe(data => this.newsObj = data);
 }

  private getNews(): Observable<any> {

  return this.http.get(this.newsUrl)
                //calling .json() on the response to return data
                .map(res => res.json())
                //...errors if any
                .catch((error:any) => Observable.throw(error.json().error || 'Server error'));
   }

And put it out:

<ion-card *ngFor="let news of newsObj">

  <ion-card-content>
    <ion-card-title>
       {{news.title.rendered}}
    </ion-card-title>
    <p>
      {{news.excerpt}}
    </p>
   </ion-card-content>
 </ion-card>

My output is:

Etupes rate l&rsquo;occasion de ramener le nul

What I want is:

Etupes rate l'occasion de ramener le nul

How I can do that in angularjs 2?

Thanks for your help.

Upvotes: 0

Views: 1512

Answers (2)

kazou
kazou

Reputation: 77

Why the pipe is not found?

@Pipe({name: 'resume'})
class resumePipe implements PipeTransform {
   transform(text: string): string {

   if(text.indexOf('<p>') != -1) {
      text.replace('<p>', '').replace('<\/p>', '');
   }

   return text.substring(0,20);
  }
}

In my template:

<p [innerHTML] = "news.excerpt.rendered | resume">

</p>

Upvotes: 0

Tiep Phan
Tiep Phan

Reputation: 12596

binding [innerHTML]=""

<ion-card-title>
   <div [innerHTML]="news.title.rendered"></div>
</ion-card-title>

<p [innerHTML]="bindingVariable">
</p>

or: create custom pipe convert html entities to character

Upvotes: 1

Related Questions