-
-
Notifications
You must be signed in to change notification settings - Fork 241
/
Copy pathtext-value-accessor.ts
54 lines (48 loc) · 2.06 KB
/
text-value-accessor.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { Directive, ElementRef, forwardRef } from "@angular/core";
import { NG_VALUE_ACCESSOR } from "@angular/forms";
import { BaseValueAccessor } from "./base-value-accessor";
import { View } from "tns-core-modules/ui/core/view";
const TEXT_VALUE_ACCESSOR = {
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => TextValueAccessor),
multi: true,
};
export type TextView = {text: string} & View;
/**
* The accessor for writing a text and listening to changes that is used by the
* {@link NgModel} directives.
*
* ### Example
* ```
* <TextField [(ngModel)]="model.test">
* ```
*/
@Directive({
selector:
"TextField[ngModel],TextField[formControlName],TextField[formControl]," +
"textField[ngModel],textField[formControlName],textField[formControl]," +
"textfield[ngModel],textfield[formControlName],textfield[formControl]," +
"text-field[ngModel],text-field[formControlName],text-field[formControl]," +
"TextView[ngModel],TextView[formControlName],TextView[formControl]," +
"textView[ngModel],textView[formControlName],textView[formControl]," +
"textview[ngModel],textview[formControlName],textview[formControl]," +
"text-view[ngModel],text-view[formControlName],text-view[formControl]," +
"SearchBar[ngModel],SearchBar[formControlName],SearchBar[formControl]," +
"searchBar[ngModel],searchBar[formControlName],searchBar[formControl]," +
"searchbar[ngModel],searchbar[formControlName],searchbar[formControl]," +
"search-bar[ngModel], search-bar[formControlName],search-bar[formControl]",
providers: [TEXT_VALUE_ACCESSOR],
host: {
"(touch)": "onTouched()",
"(textChange)": "onChange($event.value)",
},
})
export class TextValueAccessor extends BaseValueAccessor<TextView> { // tslint:disable-line:directive-class-suffix
constructor(elementRef: ElementRef) {
super(elementRef.nativeElement);
}
writeValue(value: any): void {
const normalized = super.normalizeValue(value);
this.view.text = normalized;
}
}