I am creating a ListView-based component similar to the grocery example on the {N} page. I have a + button that should add new elements 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 that when I click the "+" button, I get an exception throwing an exception. When I populate the list with code, no problem, but I need the user to be able to add new elements to the view. How to implement a dynamic ListView as I described?
EDIT:
A thrown exception is associated with a "main" thread. com.tns.NativeScriptException: js getView method call failed
! : 0 : "/data/data/org.nativescript.MyApp/files/app/tns_moudules/nativescript- angular/directives/list-view-comp.js, : 135 : 8
StackTrace: Frame: function: 'getSingleViewRecursive', :....