Skip to content

Commit c56e309

Browse files
committed
Example: *ng-if for a details TextView.
Binding change update doesn't seem to work yet.
1 parent 9d7edf4 commit c56e309

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

ng-sample/src/main-page.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {topmost} from 'ui/frame';
22
import {TextView} from 'ui/text-view';
33

44
import 'reflect-metadata';
5-
import {Component, View} from 'angular2/angular2';
5+
import {Component, View, NgIf} from 'angular2/angular2';
66

77
import {nativeScriptBootstrap} from 'nativescript-angular/application';
88

@@ -12,29 +12,35 @@ import {nativeScriptBootstrap} from 'nativescript-angular/application';
1212
}
1313
})
1414
@View({
15+
directives: [NgIf],
1516
template: `
1617
<StackLayout orientation='vertical'>
1718
<Label text='Name' fontSize='32' verticalAlignment='center' padding='20'></Label>
1819
<TextField #name text='John' fontSize='32' padding='20'></TextField>
19-
<Button [text]='buttonText' (tap)='onButtonTap($event, name)'></Button>
20+
<Button [text]='buttonText' (tap)='onSave($event, name.text)'></Button>
21+
<Button text='Toggle details' (tap)='onToggleDetails()'></Button>
22+
<TextView *ng-if='showDetails' [text]='detailsText'></TextView>
2023
</StackLayout>
2124
`,
22-
directives: []
2325
})
2426
class MainPage {
2527
public buttonText: string = "";
28+
public showDetails: boolean = false;
29+
public detailsText: string = "";
2630

2731
constructor() {
28-
this.buttonText = 'Tap me, baby, one more time!'
32+
this.buttonText = 'Save...'
33+
this.showDetails = true;
34+
this.detailsText = 'Some details and all...';
2935
}
3036

31-
onButtonTap($event, nameTextField) {
32-
console.log('onButtonTap event ' + $event);
33-
console.log('onButtonTap nameText ' + nameTextField);
34-
let e = new Error();
35-
console.log((<any>e).stack);
36-
//alert($event.object.text);
37-
alert(nameTextField.text);
37+
onSave($event, name) {
38+
console.log('onSave event ' + $event + ' name ' + name);
39+
alert(name);
40+
}
41+
onToggleDetails() {
42+
console.log('onToggleDetails current: ' + this.showDetails);
43+
this.showDetails = !this.showDetails;
3844
}
3945
}
4046

src/nativescript-angular/view_node.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {Button} from 'ui/button';
55
import {StackLayout} from 'ui/layouts/stack-layout';
66
import {Label} from 'ui/label';
77
import {TextField} from 'ui/text-field';
8+
import {TextView} from 'ui/text-view';
89
import {NativeScriptView} from 'nativescript-angular/renderer';
910
import {AST} from 'angular2/src/change_detection/parser/ast';
1011

@@ -20,6 +21,7 @@ export class ViewNode {
2021
["button", Button],
2122
["stacklayout", StackLayout],
2223
["textfield", TextField],
24+
["textview", TextView],
2325
["label", Label]
2426
]);
2527

@@ -115,6 +117,7 @@ export class ViewNode {
115117
}
116118

117119
public insertChildAt(index: number, childNode: ViewNode) {
120+
console.log('ViewNode.insertChildAt: ' + this.viewName + ' ' + index + ' ' + childNode.viewName);
118121
this.children[index] = childNode;
119122
childNode.parentNode = this;
120123

0 commit comments

Comments
 (0)