diff --git a/demo-angular/src/app/examples/reactive-forms/reactive-forms-example.component.css b/demo-angular/src/app/examples/reactive-forms/reactive-forms-example.component.css
index 66c6a32..2825acf 100644
--- a/demo-angular/src/app/examples/reactive-forms/reactive-forms-example.component.css
+++ b/demo-angular/src/app/examples/reactive-forms/reactive-forms-example.component.css
@@ -39,6 +39,10 @@ PickerPage ActionBar {
color: white;
}
+.label-bold {
+ font-weight: bold;
+}
+
.field-name-label {
font-size: 20;
font-weight: bold;
@@ -52,6 +56,12 @@ PickerPage ActionBar {
margin: 20;
}
-.green-label {
+.invalid-label {
+ color: red;
+ font-size: 20;
+}
+
+.valid-label {
color: green;
+ font-size: 20;
}
diff --git a/demo-angular/src/app/examples/reactive-forms/reactive-forms-example.component.html b/demo-angular/src/app/examples/reactive-forms/reactive-forms-example.component.html
index 765055f..637d9ba 100644
--- a/demo-angular/src/app/examples/reactive-forms/reactive-forms-example.component.html
+++ b/demo-angular/src/app/examples/reactive-forms/reactive-forms-example.component.html
@@ -14,9 +14,12 @@
-
+
-
-
-
+
+
+
+
+
+
>
diff --git a/demo-angular/src/app/examples/reactive-forms/reactive-forms-example.component.ts b/demo-angular/src/app/examples/reactive-forms/reactive-forms-example.component.ts
index d796d59..c92d665 100644
--- a/demo-angular/src/app/examples/reactive-forms/reactive-forms-example.component.ts
+++ b/demo-angular/src/app/examples/reactive-forms/reactive-forms-example.component.ts
@@ -1,9 +1,10 @@
-import { Component, OnInit, ViewChild } from "@angular/core";
+import { Component, AfterViewInit, ViewChild } from "@angular/core";
import { FormBuilder, FormGroup, FormControl, Validators } from "@angular/forms";
import { RouterExtensions } from "nativescript-angular/router";
import { ObservableArray } from "tns-core-modules/data/observable-array/observable-array";
import { PickerFieldComponent } from "nativescript-picker/angular";
import { EventData } from "tns-core-modules/ui/core/view/view";
+import { View } from "tns-core-modules/ui/core/view";
@Component({
selector: "ns-reactive-forms-example",
@@ -11,7 +12,7 @@ import { EventData } from "tns-core-modules/ui/core/view/view";
styleUrls: ["reactive-forms-example.component.css"],
templateUrl: "./reactive-forms-example.component.html"
})
-export class ReactiveFormsExampleComponent implements OnInit {
+export class ReactiveFormsExampleComponent {
public pickerItems: ObservableArray;
@ViewChild("picker", { static: false }) pickerComp: PickerFieldComponent;
@@ -33,14 +34,8 @@ export class ReactiveFormsExampleComponent implements OnInit {
});
}
- ngOnInit(): void {
- this.pickerClassName = (this.pickerComp.nativeElement).className;
- }
-
public movieForm: FormGroup;
- public pickerClassName: string;
-
public goBack() {
this.routerExtensions.backToPreviousPage();
}
@@ -58,15 +53,11 @@ export class ReactiveFormsExampleComponent implements OnInit {
}
public pickerOpened(args: EventData) {
- this.pickerClassName = (args.object).className;
-
- console.log("Picker > Opened; class:", this.pickerClassName);
+ console.log("Picker > Opened; class:", (args.object).className);
}
public pickerClosed(args: EventData) {
- this.pickerClassName = (args.object).className;
-
- console.log("Picker > Closed; class:", this.pickerClassName);
+ console.log("Picker > Closed; class:", (args.object).className);
}
}
diff --git a/src/angular/nativescript-picker.directives.ts b/src/angular/nativescript-picker.directives.ts
index 5c457cd..b114050 100644
--- a/src/angular/nativescript-picker.directives.ts
+++ b/src/angular/nativescript-picker.directives.ts
@@ -1,7 +1,8 @@
-import { ChangeDetectionStrategy, Component, ElementRef, forwardRef, IterableDiffers } from "@angular/core";
+import { ChangeDetectionStrategy, Component, ElementRef, forwardRef, IterableDiffers, AfterContentInit, OnDestroy } from "@angular/core";
import { TemplatedItemsComponent, TEMPLATED_ITEMS_COMPONENT } from "nativescript-angular/directives/templated-items-comp";
import { PickerField } from "../picker";
import { PickerValueAccessor } from "./nativescript-picker.accessors";
+import { View } from "tns-core-modules/ui/core/view";
@Component({
selector: "PickerField",
@@ -12,17 +13,40 @@ import { PickerValueAccessor } from "./nativescript-picker.accessors";
changeDetection: ChangeDetectionStrategy.OnPush,
providers: [{ provide: TEMPLATED_ITEMS_COMPONENT, useExisting: forwardRef(() => PickerFieldComponent) }]
})
-export class PickerFieldComponent extends TemplatedItemsComponent {
+export class PickerFieldComponent extends TemplatedItemsComponent implements AfterContentInit {
+ private _className: string;
+
public get nativeElement(): PickerField {
return this.templatedItemsView;
}
+ public get className(): string {
+ return this._className;
+ }
+
protected templatedItemsView: PickerField;
constructor(_elementRef: ElementRef,
_iterableDiffers: IterableDiffers) {
super(_elementRef, _iterableDiffers);
}
+
+ ngAfterContentInit() {
+ super.ngAfterContentInit();
+ this.nativeElement.on("classNameChange", this.onClassNameChange.bind(this));
+ }
+
+ ngOnDestroy() {
+ if (this.nativeElement) {
+ this.nativeElement.off("classNameChange", this.onClassNameChange.bind(this));
+ }
+
+ super.ngOnDestroy();
+ }
+
+ private onClassNameChange(args) {
+ this. _className = (args.object).className;
+ }
}
export const DIRECTIVES = [PickerFieldComponent, PickerValueAccessor];
\ No newline at end of file