I'm building a ListView based component, similar to the groceries example in the {N} page. I have a "+" button, that needs to add new items to the list, I have this code:
import { Component, OnInit } from '@angular/core';
@Component({
moduleId: module.id,
selector: 'my-list',
templateUrl: 'my-list.component.html'
})
export class ListComponent implements OnInit {
private myList: CustomObject;
constructor() { }
ngOnInit() { }
addItem(){
this.myList.push(new CustomObject());
}
}
And here is the template:
<StackLayout>
<Button text="+" (tap)="addItem()" ></Button>
<ListView [items]="myList">
<template let-item="item" let-i="i">
<Label text="item.name"></Label>
</template>
</ListView>
</StackLayout>
My problem is, when I click on the "+" button, I get an undescifrable exception. When I fill the list with code, no problem, but I need the user can add new elements to the view. How is the correct way to implement a dynamic ListView like I described?
EDIT:
An uncaught Exception ocurred on "main" thread. com.tns.NativeScriptException: Calling js method getView failded
Error No suitable views found in list template! Nesting level:0 File: "/data/data/org.nativescript.MyApp/files/app/tns_moudules/nativescript-angular/directives/list-view-comp.js, line:135 column:8
StackTrace: Frame: function:'getSingleViewRecursive', file:....