#How to reset properties on a child component?
19 messages · Page 1 of 1 (latest)
Child properties ```ts
@Input() minValue: number = 0;
@Input() maxValue: number = 90;
//
@Input()
set values(v: { min: number, max: number }) {
this.minValue = v.min;
this.maxValue = v.max;
}
//
There's probably a typo in receIve and I can't get how those inputs can work.
public recieveMinMax($event: RangeType) {
this.searchForm.controls.daysOldFrom.setValue($event.min);
this.searchForm.controls.daysOldTo.setValue($event.max);
}
```It works without issue until I need to reset the values back to default.
I update the from controls properly with events but the UI doesn't update because it's not linked to the formcontrol
There's no minValue, maxValue or values property bound in your template.
I don't know what you mean with "it works"
Yeah they appear separate but in my parent component I have ```ts
daysOldFrom: new FormControl<number>(0),
daysOldTo: new FormControl<number>(90)
I set them with the values emitted.
How can I bind the values?
Works as in I am grabbing the values and filling my parent FormGroup
That's output that works, not the inputs.
@Input() min, @Input() max instead of @Input minValue...?
Yes good way to put it.
If you want to do it through inputs only
const defaultRange = {
min: 0,
max: 90
}
@Component()
export class Slider {
@Input() min = defaultRange.min
@Input() max = defaultRange.max
}
@Component({
template: `
<slider [min]="min.value" [max]="max.value"></slider>
`
})
export class Parent {
min = new FormControl(defaultRange.min)
max = new FormControl(defaultRange.max)
reset() {
this.min.reset()
this.max.reset()
}
}
How can it work bottom-up? 🤔
You're sharing a primitive, it will be passed by value.
Changes in child's min will not be reflected in parent's one.
it's a one-way binding, parent controls the slider
I'm assuming there is a change event to set the parent
Ok.
"If you want to do it through inputs only" was misleading. 👍