After successfully retrieving data and logging it in the console of the component.ts file, I encountered an issue where the data is not displaying on the template. My goal is to present the data in a table, but for now, I am attempting to show it within a
TAG
.import { Component, OnInit } from '@angular/core';
import { CosterService } from 'projects/tradefigure-lib/src/lib/pages/blinkcoster/coster.service';
import { FormBuilder,FormsModule, ReactiveFormsModule, Validators } from '@angular/forms';
import { commodity, ICommodity } from 'projects/tradefigure-lib/src/lib/pages/blinkcoster/ICommodities.schema';
import { CrudtableService } from '../crudtable.service';
@Component({
standalone: true,
imports: [
CommonModule,
FormsModule,
ReactiveFormsModule,
],
selector: 'app-commodity',
templateUrl: '
',
styleUrls: ['./commodity.component.css']
})
export class CommodityComponent implements OnInit {
// commodity: commodity = new commodity();
commodity$!: ICommodity[];
commoditys = this.commodity$
isEditing: boolean = false
title = 'crud';
commodity: ICommodity [] = []
constructor(
private fb: FormBuilder,
private CosterService: CosterService,
private crud: CrudtableService,
) { }
ngOnInit(): void {
this.form;
this.crud.getAll().subscribe({
next: (res) => {
this.commodity
console.log(res)
}
})
}
<div *ngFor="let commodity of commodity$ ">
<p>{{commodity.offtalkerpriceOID}}</p>
<p>{{commodity.commodityDescription}}</p>
<p>{{commodity.unitPrice}}</p>
<p>{{commodity.unitOfMeasure}}</p>
</div>
I have attempted passing the data as an observable and utilizing the async pipe on the template without success.
The data is alerted and logged in the console, however, when using *ngFor to display it on the template, the template remains white.
If you have any solutions to this problem, please advise. Thank you!