Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions ng-sample/app/list-test-async.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { Component, Input, ChangeDetectionStrategy } from 'angular2/core';
import { Observable as RxObservable } from 'rxjs/Observable';
import { Observable, WrappedValue } from 'data/observable';

class DataItem {
constructor(public id: number, public name: string) { }
}

@Component({
selector: 'list-test-async',
template: `
<ListView [items]="myItems | async" (itemTap)="onItemTap($event)">
<item-template>
<template #item="item" #i="index" #odd="odd" #even="even">
<StackLayout [class.odd]="odd" [class.even]="even">
<Label [text]='"index: " + item.name'></Label>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the text binding should probably read "name: " + item.name

</StackLayout>
</template>
</item-template>
</ListView>
`,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class ListTestAsync {
public myItems: RxObservable<Array<DataItem>>;

constructor() {
var items = [];
for (var i = 0; i < 3; i++) {
items.push(new DataItem(i, "data item " + i));
}

var subscr;
this.myItems = RxObservable.create(subscriber => {
subscr = subscriber;
subscriber.next(WrappedValue.wrap(items));
return function () {
console.log("Unsubscribe called!!!");
}
});

let counter = 2;
let intervalId = setInterval(() => {
counter++;
console.log("Adding " + counter + "-th item");
items.push(new DataItem(counter, "data item " + counter));
subscr.next(WrappedValue.wrap(items));
}, 1000);

setTimeout(() => {
clearInterval(intervalId);
}, 15000);
}

public onItemTap(args) {
console.log("------------------------ ItemTapped: " + args.index);
}
}
6 changes: 4 additions & 2 deletions ng-sample/app/main-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {Page} from 'ui/page';
import {nativeScriptBootstrap} from './nativescript-angular/application';
// import {RendererTest} from './renderer-test';
//import {Benchmark} from './benchmark';
import {ListTest} from './list-test';
//import {ListTest} from './list-test';
import {ListTestAsync} from './list-test-async';

export function createPage() {
var page = new Page();
Expand All @@ -19,7 +20,8 @@ export function createPage() {
console.log('BOOTSTRAPPING...');
//nativeScriptBootstrap(Benchmark, []).then((appRef) => {
// nativeScriptBootstrap(RendererTest, []).then((appRef) => {
nativeScriptBootstrap(ListTest, []).then((appRef) => {
//nativeScriptBootstrap(ListTest, []).then((appRef) => {
nativeScriptBootstrap(ListTestAsync, []).then((appRef) => {
profiling.stop('ng-bootstrap');
console.log('ANGULAR BOOTSTRAP DONE.');
}, (err) =>{
Expand Down