#How to reset properties on a child component?

19 messages · Page 1 of 1 (latest)

rare crane
#

Hello,

I have a two range slider that was custom made.

        <fcs-two-way-range-slider (output)="recieveMinMax($event)" [min]="0" [max]="90"></fcs-two-way-range-slider>
```I have the parent that holds the values emitted. 
I need to set the properties in the child back to their defaults. How might I do that?
#

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;
}
//

barren crater
#

There's probably a typo in receIve and I can't get how those inputs can work.

rare crane
#

I update the from controls properly with events but the UI doesn't update because it's not linked to the formcontrol

barren crater
#

There's no minValue, maxValue or values property bound in your template.
I don't know what you mean with "it works"

rare crane
#

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?

rare crane
barren crater
#

That's output that works, not the inputs.

clever plank
#

@Input() min, @Input() max instead of @Input minValue...?

rare crane
hidden star
#

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()
  }
}
barren crater
hidden star
#

I'm assuming there is a change event to set the parent

barren crater
#

Ok.
"If you want to do it through inputs only" was misleading. 👍