Slider validation using template driven forms in Angular Range slider component
17 Nov 20222 minutes to read
Slider can be validated in Angular using Template-driven forms.
- The following CSS classes will be added on Slider component based on the action done by user.
Class if true | Class if false | state |
---|---|---|
ng-touched |
ng-untouched |
The control has been visited. |
ng-dirty |
ng-pristine |
The control’s value has changed. |
ng-valid |
ng-invalid |
The control’s value is valid. |
import { Component, ViewEncapsulation, ViewChild } from '@angular/core';
import { SliderModule } from '@syncfusion/ej2-angular-inputs';
import {NgForm} from '@angular/forms';
@Component({
selector: 'my-app',
templateUrl: 'app/template.html',
styleUrls:['index.css'],
encapsulation: ViewEncapsulation.None
})
export class AppComponent {
value; validated;
@ViewChild('sliderForm') form: NgForm;
onSubmit() {
this.validated = true;
console.log(this.form.valid)
}
ngOnInit() {
this.value =70;
}
}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { SliderValidaton } from './sliderValidation';
import { SliderModule } from '@syncfusion/ej2-angular-inputs';
import { FormsModule } from '@angular/forms';
/**
* Module
*/
@NgModule({
imports: [
BrowserModule,
SliderModule,
FormsModule
],
declarations: [AppComponent, SliderValidaton],
bootstrap: [AppComponent]
})
export class AppModule { }
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';
enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule);