@ngx-reflective-forms/core
v0.0.8
Published
Core NgxReflectiveForms Package
Downloads
3
Readme
Getting Started
export class TestFormModel {
name: string;
surname: string;
attributeWithoutControl = 10;
}
@Injectable()
export class TestFormGroup extends FormGroup<TestFormModel> {
@Control()
@Default("Miguel")
@Validator(TestFormValidator.validateName)
public name: TextFormControl = undefined as any;
@Control()
@Default("Franken")
public surname: TextFormControl = undefined as any;
}
export class TestFormValidator {
public static validateName(this: TextFormControl): void {
if (this.value.length > 5) {
throw new ValidationError("Max. 5 Characters");
}
}
}
@Component({
selector: "app-root",
templateUrl: "./app.component.html",
providers: [TestFormGroup],
})
export class AppComponent implements OnInit {
constructor(private form: TestFormGroup) {
}
ngOnInit(): void {
this.form.init();
}
}