#angular #html #angular7
#angular #HTML #angular7
Вопрос:
Я впервые работаю над Angular и пытаюсь отобразить некоторые данные. Данные находятся в массиве
[Я, Три, четыре]
Я пытаюсь выполнить цикл через него, чтобы распечатать данные, но это не работает. В настоящее время я делаю это таким образом
<ng-container matColumnDef="channel">
<th mat-header-cell *matHeaderCellDef> Channel </th>
<td mat-cell *matCellDef="let element"> {{element.channel}} </td>
</ng-container>
и то, что я получаю в столбце, это
[Я, Три, четыре]
channel: "[ME, WE, US]"
end: "2018-03-29T08:00:00Z"
states: "[NY, Non-NY]"
start: "2018-03-29T08:00:00Z"
trans: "[Act:Add]"
как мне удалить [] из данных? Спасибо
Ответ №1:
Попробуйте что-то вроде этого:
<ng-container matColumnDef="channel">
<th mat-header-cell *matHeaderCellDef> Channel </th>
<td mat-cell *ngFor="let element of nameOfArray"> {{element}}</td>
</ng-container>
Ответ №2:
если ваш array / json выглядит следующим образом
channel: "[ME, WE, US]"
end: "2018-03-29T08:00:00Z"
states: "[NY, Non-NY]"
start: "2018-03-29T08:00:00Z"
trans: "[Act:Add]"
чем добавлять html
<ng-container *ngFor="let element of nameOfArray">
<th mat-header-cell> Channel </th>
<th mat-header-cell> end</th>
<th mat-header-cell> states</th>
<th mat-header-cell> start</th>
<th mat-header-cell> trans</th>
<td mat-cell >{{element.channel}}</td>
<td mat-cell >{{element.end}}</td>
<td mat-cell >{{element.states}}</td>
<td mat-cell >{{element.start}}</td>
<td mat-cell >{{element.trans}}</td>
</ng-container>
если вы хотите удалить это
end: "2018-03-29T08:00:00Z"
чем вы не можете получить (доступ) в своем rest
или не можете переписать в свой html, удалите приведенный выше код.