Skip to content

Implement with Angular  #5

@leocaseiro

Description

@leocaseiro

Hi @rajivnarayana,

I'm trying to implement this plugin with Angular, however, I'm struggling to register the custom <itemTemplate> and the <headerTemplate>.

The only thing missing is customising the template which by default, is showing: [object Object].

I know in A{N} I have to create my item using let-item, but let doesn't work with any other element besides <template>:

ERROR

 "let-" is only supported on template elements. ("     
                <SectionedListView [items]="sectionedArray" rowHeight="44">
                    <itemTemplate [ERROR ->]let-item="item">
                        <Label [text]="item.name"></Label>
                    </itemTemplate>
        "): SectionedListViewComponent@4:26

Do you know how does work?

MY CODE:

import {Component} from '@angular/core';
import {registerElement} from "nativescript-angular/element-registry";

var observableSectionArrayModule = require("observable-sectioned-array");

registerElement('SectionedListView', () => require("nativescript-sectioned-list-view").SectionedListView);

@Component({
    selector: 'core-sectioned-listview',
    template: `
        <SectionedListView [items]="sectionedArray" rowHeight="44">
            <itemTemplate let-item="item">
                <Label [text]="item.name"></Label>
            </itemTemplate >
            <headerTemplate>
                <Label [text]="$value"></Label>
            </headerTemplate>
        </SectionedListView>
    `,
})
export class CoreSectionedListView {

    items: any;
    sectionedArray: any;

    constructor() {
        this.items = [
            {"name" : "Alice", gender:"female"},
            {"name": "Adam", gender: "male"},
            {"name": "Bob", gender: "male"},
            {"name": "Brittany", gender: "female"},
            {"name": "Evan", gender: "male"}
        ];

        var boys = this.items.filter(function(student) { return student.gender ==="male";});
        var girls = this.items.filter(function(student) { return student.gender ==="female";});

        this.sectionedArray = new observableSectionArrayModule.ObservableSectionArray();
        this.sectionedArray.addSection("Boys", boys);
        this.sectionedArray.addSection("Girls", girls);
    }

}

Result:
sectioned-array-list-view

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions