import { Component, forwardRef, Input, OnInit } from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
@Component({
selector: 'app-password-input',
templateUrl: './password-input.component.html',
providers: [
{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => PasswordInputComponent),
multi: true
}
]
})
export class PasswordInputComponent implements OnInit, ControlValueAccessor {
constructor() {}
writeValue(obj: any): void {
this.Value = obj;
}
registerOnChange(fn: any): void {
this.onChange = fn;
}
registerOnTouched(fn: any): void {
this.onTouch = fn;
}
setDisabledState?(isDisabled: boolean): void {
this.disabled = isDisabled;
}
onChange: any = () => {};
onTouch: any = () => {};
disabled?: boolean;
ngOnInit(): void {}
/** Password value */
public value: string;
set Value(val) {
// this value is updated by programmatic changes
if (val !== undefined && this.value !== val) {
this.value = val;
this.onChange(val);
this.onTouch(val);
}
}
get Value(): string {
return this.value;
}
}
Tuesday, 20 October 2020
Implementing ControlValueAccessor
Etykiety:
Angular,
code,
in English,
in Polish,
TypeScript
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment