|
|
@ -1,23 +1,14 @@ |
|
|
|
import { Component } from '@angular/core'; |
|
|
|
import { FormArray, FormBuilder } from '@angular/forms'; |
|
|
|
|
|
|
|
import { arrayCannotEmpty } from './validators/array-cannot-empty.validator'; |
|
|
|
import { FormControl } from '@angular/forms'; |
|
|
|
import { decimalValidator } from './validators/decimal.validator'; |
|
|
|
|
|
|
|
@Component({ |
|
|
|
selector: 'my-app', |
|
|
|
templateUrl: './app.component.html', |
|
|
|
styleUrls: ['./app.component.css'], |
|
|
|
styleUrls: [ './app.component.css' ] |
|
|
|
}) |
|
|
|
export class AppComponent { |
|
|
|
readonly form = this.fb.group({ |
|
|
|
tasks: this.fb.array([], { |
|
|
|
validators: [arrayCannotEmpty]? |
|
|
|
}), |
|
|
|
readonly formControl = new FormControl(0, { |
|
|
|
validators: [decimalValidator(2, 1)] |
|
|
|
}); |
|
|
|
|
|
|
|
get tasks(): FormArray { |
|
|
|
return this.form.get('tasks') as FormArray; |
|
|
|
} |
|
|
|
|
|
|
|
constructor(private fb: FormBuilder) {} |
|
|
|
} |