-
-
Save jorroll/09b8580ab33bfce266221839f399fdd5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare const stringDateValidator: ValidatorFn; | |
declare const stringToDate: (value: string) => Date | null; | |
declare const dateToString: (value: Date | null) => string; | |
class ExampleFourComponent implements OnInit { | |
inputControl = new FormControl('', { | |
validators: stringDateValidator, | |
}); | |
dateControl = new FormControl<Date | null>(null); | |
ngOnInit() { | |
this.inputControl.events | |
.pipe( | |
map(event => { | |
if (event.type === 'StateChange' && event.changes.has('value')) { | |
const changes = new Map(event.changes); | |
changes.set('value', stringToDate(changes.get('value'))); | |
return { | |
...event, | |
changes, | |
}; | |
} | |
return event; | |
}), | |
) | |
.subscribe(this.dateControl.source); | |
this.dateControl.events | |
.pipe( | |
map(event => { | |
if (event.type === 'StateChange' && event.changes.has('value')) { | |
const changes = new Map(event.changes); | |
changes.set('value', dateToString(changes.get('value'))); | |
return { | |
...event, | |
changes, | |
}; | |
} | |
return event; | |
}), | |
) | |
.subscribe(this.inputControl.source); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment