I am currently working on an HTML project where I need to display objects from an array using Angular. My goal is to only show the objects in the array that are not empty. While I have managed to hide the content of empty objects, the boxes holding this content still appear. I would appreciate any assistance in fixing this issue.
HTML:
<div class=content>
<div class=data-item *ngFor="let item of dataSource">
<div *ngIf="item.Value != ''" >
<div>{{item.Header}}</div>
<div>{{item.Value}}</div>
</div>
</div>
</div>
CSS:
.content {
width: 100%;
display: flex;
flex-wrap: wrap;
}
.data-item{
flex: 0 0 21%;
border-style: solid;
}
TS:
import { Component, VERSION } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
name = 'Angular ' + VERSION.major;
dataSource: items[] = [
{Header: 'Header A1', Value: 123},
{Header: 'Header B2', Value: 234},
{Header: 'Header C3', Value: ''},
{Header: 'Header D4', Value: 456},
{Header: 'Header E5', Value: ''},
{Header: 'Header F6', Value: 678},
{Header: 'Header G7', Value: 789},
]
}
export interface items{
Header: string;
Value: any;
}
Check out the screenshot of the final rendered HTML: Rendered HTML