Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
get passwordState() {
return cast(this.formState.controls.password);
}
dateValueConverter: NgrxValueConverter = {
convertViewToStateValue(value) {
if (value === null) {
return null;
}
// the value provided by the date picker is in local time but we want UTC so we recreate the date as UTC
value = new Date(Date.UTC(value.getFullYear(), value.getMonth(), value.getDate()));
return NgrxValueConverters.dateToISOString.convertViewToStateValue(value);
},
convertStateToViewValue: NgrxValueConverters.dateToISOString.convertStateToViewValue,
};
constructor(private actionsSubject: ActionsSubject) { }
reset() {
this.actionsSubject.next(new SetValueAction(INITIAL_STATE.id, INITIAL_STATE.value));
this.actionsSubject.next(new ResetAction(INITIAL_STATE.id));
}
submit() {
if (this.formState.isInvalid) {
return;
}
this.submittedValue = this.formState.value;
}
get metaState(): FormGroupState {
return this.formState.controls.meta as FormGroupState;
}
dateValueConverter: NgrxValueConverter = {
convertViewToStateValue(value) {
if (value === null) {
return null;
}
// the value provided by the date picker is in local time but we want UTC so we recreate the date as UTC
value = new Date(Date.UTC(value.getFullYear(), value.getMonth(), value.getDate()));
return NgrxValueConverters.dateToISOString.convertViewToStateValue(value);
},
convertStateToViewValue: NgrxValueConverters.dateToISOString.convertStateToViewValue,
};
ngAfterViewInit() {
const isErrorState = (state: AbstractControlState) => state.isInvalid && (state.isDirty || state.isTouched || state.isSubmitted);
// sadly, material 2 only properly integrates its error handling with @angular/forms; therefore
// we have to implement a small hack to make error messages work
const meta = () => this.formState.controls.meta as FormGroupState;
this.inputs.find(i => i.id === 'priority')!._isErrorState = () => isErrorState(meta().controls.priority);
this.inputs.find(i => i.id === 'duedate')!._isErrorState = () => isErrorState(meta().controls.duedate);
this.inputs.find(i => i.id === 'text')!._isErrorState = () => isErrorState(this.formState.controls.text);
}
onSubmit() {
if (this.formState.isInvalid) {
return;
this.submittedValue$ = store.pipe(select(s => s.material.submittedValue));
}
hobbyOptions = ['Sports', 'Video Games'];
dateValueConverter: NgrxValueConverter = {
convertViewToStateValue(value) {
if (value === null) {
return null;
}
// the value provided by the date picker is in local time but we want UTC so we recreate the date as UTC
value = new Date(Date.UTC(value.getFullYear(), value.getMonth(), value.getDate()));
return NgrxValueConverters.dateToISOString.convertViewToStateValue(value);
},
convertStateToViewValue: NgrxValueConverters.dateToISOString.convertStateToViewValue,
};
reset() {
this.store.dispatch(new SetValueAction(INITIAL_STATE.id, INITIAL_STATE.value));
this.store.dispatch(new ResetAction(INITIAL_STATE.id));
}
submit() {
this.formState$.pipe(
take(1),
filter(s => s.isValid),
map(fs => new SetSubmittedValueAction(fs.value)),
).subscribe(this.store);
}
}
convertViewToStateValue(value) {
if (value === null) {
return null;
}
// the value provided by the date picker is in local time but we want UTC so we recreate the date as UTC
value = new Date(Date.UTC(value.getFullYear(), value.getMonth(), value.getDate()));
return NgrxValueConverters.dateToISOString.convertViewToStateValue(value);
},
convertStateToViewValue: NgrxValueConverters.dateToISOString.convertStateToViewValue,
convertViewToStateValue(value) {
if (value === null) {
return null;
}
// the value provided by the date picker is in local time but we want UTC so we recreate the date as UTC
value = new Date(Date.UTC(value.getFullYear(), value.getMonth(), value.getDate()));
return NgrxValueConverters.dateToISOString.convertViewToStateValue(value);
},
convertStateToViewValue: NgrxValueConverters.dateToISOString.convertStateToViewValue,
convertViewToStateValue(value) {
if (value === null) {
return null;
}
// the value provided by the date picker is in local time but we want UTC so we recreate the date as UTC
value = new Date(Date.UTC(value.getFullYear(), value.getMonth(), value.getDate()));
return NgrxValueConverters.dateToISOString.convertViewToStateValue(value);
},
convertStateToViewValue: NgrxValueConverters.dateToISOString.convertStateToViewValue,
import { FormValue, State } from './value-conversion.reducer';
@Component({
selector: 'ngf-value-conversion',
templateUrl: './value-conversion.component.html',
styleUrls: ['./value-conversion.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ValueConversionPageComponent {
formState$: Observable>;
constructor(store: Store) {
this.formState$ = store.pipe(select(s => s.valueConversion.formState));
}
dateToISOString = NgrxValueConverters.dateToISOString;
}