-
Notifications
You must be signed in to change notification settings - Fork 18
/
common.ts
32 lines (25 loc) · 949 Bytes
/
common.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
import * as moment from "moment";
import { NG_VALIDATORS, NG_VALUE_ACCESSOR } from "@angular/forms";
import { forwardRef, Provider, Type } from "@angular/core";
export type OnChangeHandler = (value: any) => void;
export type OnTouchedHandler = (value: any) => void;
export interface MomentParseFunction {
(value: any, format?: string | string[], strictParsing?: boolean): moment.Moment;
}
export function local(value?: any, format?: string | string[], strictParsing?: boolean): moment.Moment {
return moment(value, format, strictParsing);
}
export function ControlValueAccessorProviderFactory(type: Type<any>): Provider {
return {
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => type),
multi: true
};
}
export function ValidatorProviderFactory(type: Type<any>): Provider {
return {
provide: NG_VALIDATORS,
useExisting: forwardRef(() => type),
multi: true
};
}