Data has not been loaded into the Angular NGX Datatable

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.

Answer №1

Is the property "name" present in the product data?

If not, you have two options: either modify the name="name" attribute to reflect the correct property name, or add the following code snippet (replace differenProp with the actual property containing the name):

...
<ng-template ngx-datatable-header-template>
  Name
</ng-template>
<ng-template ngx-datatable-cell-template let-row="row" let-value="value">
  {{ row.differenProp }}
</ng-template>
...

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating dynamic components with constructor parameters in Angular 9

Having trouble passing a value to the constructor in the component generation code. Check out the original code here: https://stackblitz.com/edit/angular-ivy-tcejuo private addComponent(template: string) { class TemplateComponent { @ViewChild( ...

The index type '{id:number, name:string}' is not compatible for use

I am attempting to generate mock data using a custom model type that I have created. Model export class CategoryModel { /** * Properties */ public id : number; public name : string; /** * Getters */ get Id():number{ return this.id; ...

Updating Angular 2 components using BaobabWould you like to learn how to

Exploring Baobab as a potential solution for developing Flux applications with Angular 2 has piqued my interest, but I have yet to come across any examples. My primary query revolves around the process of 'subscribing' an Angular Component to Ba ...

Creating a Typescript interface with at least one specified type

I've recently delved into using typescript. Currently, I'm faced with a scenario where I need to import available types from backend endpoints. In one specific instance, an endpoint can support two types as parameters. Example: interface B ext ...

"Firebase hosting in Angular experienced an error and was unsuccessful

I am currently using this tutorial to develop a progressive web app with Angular. After creating the project on Firebase, I was able to successfully deploy it. You are now initializing a Firebase project in this directory: /Users/nitish/development/ng ...

Develop an object's attribute using form in the Angular 5 framework

I am looking to create an object for a location that includes two parameters. While I can easily create an array of strings using FormGroup, I am unsure of how to create an object with two parameters nested inside it. Below is the code snippet I currently ...

The combination of Angular's *ngIf directive and ng-template is causing issues

When I have up to 3 icons, I require less space compared to when I have 3 icons or more. To address this issue, I have implemented the following code that utilizes both *ngIf and ng-template. Unfortunately, the implementation is not functioning as expect ...

I am experiencing issues with certain Tailwind CSS classes not functioning properly in my Angular 16 project

I have embarked on an exciting journey of developing an Angular 16 project integrated with the latest version of Tailwind CSS, V3. Following the official documentation, I expected everything to work seamlessly. However, I am perplexed as to why some classe ...

Issue with PrimeNG functionality in Angular4 environment

I encountered an issue while trying to implement PrimeNG into my Angular 4 project. Despite following the setup steps outlined on their website, I received an error message when attempting to import a module. Here's an example of the error: Can' ...

Tips for determining if an HTMLElement has already been created

One issue I'm facing is with a third party component that emits an "onCellEdit" event and passes a cell element as a parameter. My goal is to automatically select the entire text in the input element generated inside this cell when the event occurs. ...

What is the best way to eliminate the # symbol in angular 5 URLs?

Currently, I am working on a project in Angular 5 and I need to remove the hash symbol (#) from my URL. The current URL looks like this: http://localhost:4200/#/product/add. While it works fine after being published on my domain, I encounter a 404 error ...

How to Retrieve a Symbol in TypeScript

In the code snippet below, there is a function named factory that returns a Symbol of type Bob. However, TypeScript appears to forget the type of the return value immediately, leading to an error when trying to assign the return value to variable test one ...

I am unable to access the 'UserName' property in Angular 2 because it is undefined

I have tried multiple solutions, but none of them have helped me solve this issue... I am struggling to identify the problem in my code... HTML CODE :: <input type="text" class="form-control" placeholder="Please Enter Your Username" [(ngModel)]="curr ...

What is the appropriate directory to place the `typescript` package in order for WebStorm to recognize it?

According to the information on this webpage: The Configure TypeScript Compiler dialog box provides two options: Detect: WebStorm will look for a typescript package within the current project. If it finds one, it will use that package. Otherwise ...

The custom native date adapter is facing compatibility issues following the upgrade of Angular/Material from version 5 to 6

In my Angular 5 application, I had implemented a custom date adapter as follows: import {NativeDateAdapter} from "@angular/material"; import {Injectable} from "@angular/core"; @Injectable() export class CustomDateAdapter extends NativeDateAdapter { ...

Basic Karma setup with Typescript - Error: x is undefined

I am trying to configure a basic test runner using Karma in order to test a TypeScript class. However, when I attempt to run the tests with karma start, I encounter an error stating that ReferenceError: Calculator is not defined. It seems like either the ...

The promise is unexpectedly fulfilled ahead of schedule without returning the expected value from an AXIOS call

My current challenge involves making a request to a service that rapidly generates multiple strings. The problem lies in returning a promise from this service, as I lack control over the string-generation process. It is crucial for me to return a promise ...

Issues with Angular Reactive Forms Validation behaving strangely

Working on the login feature for my products-page using Angular 7 has presented some unexpected behavior. I want to show specific validation messages for different errors, such as displaying " must be a valid email " if the input is not a valid email addre ...

Mastering Nested *ngFor in Angular

I attempted to use nested for loops in Angular but I couldn't achieve the exact result I wanted. I tried different approaches, but none of them gave me the desired outcome from this nested loop function. I am looking to create a select box based on n ...

Are union types strictly enforced?

Is it expected for this to not work as intended? class Animal { } class Person { } type MyUnion = Number | Person; var list: Array<MyUnion> = [ "aaa", 2, new Animal() ]; // Is this supposed to fail? var x: MyUnion = "jjj"; // Should this actually ...