I would like to separate some data. The situation is the next. A GET a JSON from my database and it has some different columns. For example: id, name, message, type. I would like to bind the data into different divs depending on the type content.
So I want to bind just those data's which contains the required strings ( like = 'connection error')
In my html file:
<div *ngFor="let data of data.data ">{{data.type}}</div>
I want to show all the data from the JSON but on separated way. There are any way to give a requirement for the binding content ? Like this {{ data.type=''}} The requirement will be the type columns content. I try it like this:
<div *ngFor="let data of data.data; let type = connection error">
{{data.message}} {{data.id}}
</div>
<div *ngFor="let data of data.data; let type = request error">
{{data.message}} {{data.id}}
</div>
My TS is:
import { Component, OnInit, NgModule, Input} from '@angular/core';
import { ErrorsService } from './errors.service';
@Component({
selector: 'app-errors',
templateUrl: './errors.component.html',
styleUrls: ['./errors.component.css'],
})
export class ErrorsComponent implements OnInit {
data: any = [];
constructor(private errorsService: ErrorsService) { }
ngOnInit() {
this.errorsService.getAllErrors().subscribe(data => {
this.data = data
});
}
}