Многомерный массив отображает пустую строку в каждой итерации внутренней * ngFor - PullRequest
0 голосов
/ 07 февраля 2020

Ouput выглядит как Массив ответов:

    (4) [Array(2), Array(2), Array(2), Array(2)]
    0: Array(2)
    0: 0
    1: {id: 1, user_id: 1, asked: "hello", answered: null, liked: 1, …}
    length: 2
    __proto__: Array(0)
    1: Array(2)
    0: 1
    1: {id: 2, user_id: 1, asked: "Hello", answered: null, liked: 1, …}
    length: 2
    __proto__: Array(0)
    2: Array(2)
    0: 2
    1: {id: 3, user_id: 1, asked: "How are you", answered: null, liked: 1, …}
    length: 2
    __proto__: Array(0)
    3: (2) [3, {…}]
    length: 4
    __proto__: Array(0)

    TS:


      getAllMessege() {
            this.ds.getchat().subscribe((response) => {
              // for(var i = 0; i < response.length; i++) { 
              //   $('#conversation').html();
              // }
              var result = Object.keys(response).map(function(key) {
                return [Number(key), response[key]];
              });
              this.messeges = result;
              console.log(result);
            });


Component:    


<div class="outgoing_msg" *ngFor="let messege of messeges">
           <div *ngFor="let data of messege" class="sent_msg">
                <p>{{data.asked}}</p>
                <span class="time_date">{{data.created_at}}</span> 
           </div>
        </div>

Внутренний ngfor создает одну дополнительную пустую строку для каждой итерации. Он печатает этот div 'sent_msg' дважды. Убедительная просьба, есть ли какие-либо проблемы с данными или машинописью, или это может быть сам компонент. Извините за мой бедный английский sh. Заранее спасибо.

...