3

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>

3
  • 1
    You should use english for questions here... Commented Dec 8, 2016 at 0:41
  • @DawidZbiński I translated now Commented Dec 8, 2016 at 0:49
  • 1
    looking at your code this should work as expected.. see this as a reference github.com/NativeScript/nativescript-sdk-examples-ng/blob/… also check your package.json versions of all angular related dependencies and rebuild your app. Commented Dec 9, 2016 at 7:41

4 Answers 4

6

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

Sign up to request clarification or add additional context in comments.

Comments

1

Using NativeScript 4.1.1:

You do need this in the app.module:

import { NativeScriptModule } from "nativescript-angular/nativescript.module";

But then in the specific module referencing the ListView you need to import this:

import { NativeScriptUIListViewModule } from "nativescript-ui-listview/angular";

I'm using RadListView, but I think this may apply to the normal ListView as well.

Comments

0

As for now, you need import NativeScriptCommonModule from 'nativescript-angular/common' to containing module.

Comments

-1

In NativeScript 4.1.0 you have to include this module

import { NativeScriptModule } from "nativescript-angular/nativescript.module";

and add it to the imports

@NgModule({
  ...
  imports: [NativeScriptModule],
  ...
})

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.