Skip to content
Snippets Groups Projects
Commit b4d6c9a7 authored by mechtelm's avatar mechtelm
Browse files

Fix 'disabled attribute with a reactive form directive'-warning

parent d2571cd5
No related branches found
No related tags found
No related merge requests found
import { Component } from '@angular/core';
import { Component, OnInit, ViewChild } from '@angular/core';
import { ValidatorFn, Validators } from '@angular/forms';
import { MatSlider } from '@angular/material/slider';
import { SliderElement } from '../models/slider-element';
import { FormElementComponent } from '../form-element-component.directive';
......@@ -27,7 +28,6 @@ import { FormElementComponent } from '../form-element-component.directive';
[style.height.%]="100">
<mat-slider
[formControl]="elementFormControl"
[disabled]="elementModel.readOnly"
[style.width.%]="100"
[max]="elementModel.maxValue"
[min]="elementModel.minValue">
......@@ -53,9 +53,9 @@ import { FormElementComponent } from '../form-element-component.directive';
':host ::ng-deep .mat-slider-thumb{border-radius: 0; width: 10px; height: 40px; bottom: -15px}'
]
})
export class SliderComponent extends FormElementComponent {
export class SliderComponent extends FormElementComponent implements OnInit {
@ViewChild(MatSlider) inputElement!: MatSlider;
elementModel!: SliderElement;
// todo: ?? setting disabled attribute of slider may cause 'changed after checked' error
get validators(): ValidatorFn[] {
const validators: ValidatorFn[] = [];
......@@ -64,4 +64,9 @@ export class SliderComponent extends FormElementComponent {
}
return validators;
}
ngOnInit(): void {
super.ngOnInit();
this.inputElement.disabled = this.elementModel.readOnly;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment