Angular 5 не может отобразить массив объектов в HTML - PullRequest
0 голосов
/ 01 сентября 2018

У меня есть массив строк, и каждый элемент вызывается в функции param для получения результата в формате JSON. Я хочу отображать результат в каждом элементе, но он не отображается в HTML. формат результата переменной this.tones выглядит следующим образом:

[
 {score: 0.610885, tone_id: "anger", tone_name: "Colère"},
 {score: 0.506763, tone_id: "analytical", tone_name: "Analytique"}
]

Каждый элемент имеет разные результаты, поэтому он может иметь два объекта в массиве или один или ни одного

Мой код в component.ts:

this.accountService.getFeedbacks().subscribe(res => {
      this.feedbacks = res as Feedback[];      
      //  console.log(this.feedbacks);
      this.feedbacks.map(item => {
        this.message.push(item.feedback);
        localStorage.setItem('list_assigned', JSON.stringify(this.message));
        // console.log(this.message);
      })
      }, err => {
        console.log(err);
    });

// test is the array of strings which each item will be treated in TestAnalyser() function
var test = JSON.parse(localStorage.getItem('list_assigned'));
    console.log(test);

    test.map(item => {

      this.toneAnalyser.TestAnalyser(item).subscribe(res => {
        this.tone = res;
        this.tones = this.tone.document_tone.tones;
        this.tones.map(obj => {
            this.scores = obj.score;
            this.toneTexts= obj.tone_name;
            // console.log(this.scores, this.toneTexts)  
            console.log(this.tones);
        })
        // console.log(this.tones);
      }, err => {
        console.log(err);
      });

    });

component.html:

<table class="table table-striped">
            <thead>
              <tr>
                <th scope="col">#</th>
                <th scope="col">Message de retour</th>
                <th scope="col">Score</th>
                <th scope="col">Emotion</th>
              </tr>
            </thead>
            <tbody *ngIf="feedbacks.length">
              <tr *ngFor="let fd of feedbacks; let t of tones; let i = index">
                <td scope="row">{{i + 1}}</td>
                <td>{{fd.feedback}}</td>
                <td>{{t.score}}</td>
                <td>{{t.tone_name}}</td>
              </tr>
            </tbody>
          </table>

Любая помощь очень ценится!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...