Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NativeScript Angular ListView Rendering [object Object]

I'm trying to play a ListView in Nativescript + Angular and I can not render the defined template. My ListView is showing [object Object] instead of the template. I always get that result. If the items in my array are a String, the text is displayed on the line, if it is an object it insists on not showing my template and displaying [object Object].

The result I get is this:

enter image description here

Below is my code

eventos.component.ts

import {Component, OnInit, ChangeDetectionStrategy, Input} from '@angular/core';


@Component({
  selector: "PrincipalEventosListView",
  templateUrl: "pages/principal/eventos/eventos.component.html",
  changeDetection: ChangeDetectionStrategy.OnPush,
})

export class PrincipalEventosComponent  {

  public registros: Array<any>;

    constructor() {

        this.registros = [];
        this.registros.push({tipo: "Teste 1"});
        this.registros.push("String no lugar de objeto.");
        this.registros.push({tipo: "Teste 3"});
        this.registros.push(123);
        this.registros.push({tipo: "Teste 4"});
    }

}

eventos.component.html

<GridLayout>

<ListView [items]="registros">
    <template let-item="item">
        <Label [text]="item.tipo"></Label>
    </template>
</ListView>

like image 812
Eduardo Lagares Avatar asked Dec 07 '25 19:12

Eduardo Lagares


1 Answers

I had the same issue, I fix it by including import { NativeScriptModule } from "nativescript-angular/platform"; in the module containing the list.

like image 64
bobby nguyen Avatar answered Dec 09 '25 16:12

bobby nguyen