As a beginner in Angular, I am struggling to set data from the module.
ngOnInit() {
this.populate();
}
public populate() {
this.productService.getAllProduct('6f453f89-274d-4462-9e4b-c42ae60344e4').subscribe(prod => {
this.products = prod.map(prx => prx.request);
console.log(this.products);
});
The issue lies with displaying the data in the HTML code. Here is the snippet:
<ngx-datatable style="height: 500px; box-shadow: none" class="material fullscreen" [columnMode]="'force'"
[headerHeight]="50" [footerHeight]="50" [rowHeight]="60" [scrollbarV]="true" [rows]="products">
<ngx-datatable-column name="name">
<ng-template ngx-datatable-header-template>
Name
</ng-template>
</ngx-datatable-column>
</ngx-datatable>
Despite logging the data successfully, it does not reflect in the datatable as expected. To address this, I have introduced additional code in the constructor.
constructor(private productService: ProductService, public modalService: NgbModal) {
this.products = [new Product()];
}
Although the existing code functions properly, an empty row appears in the datatable before the actual data is populated.