Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. import { AkitaNgFormsManager } from '@datorama/akita-ng-forms-manager';
  2. import { untilDestroyed } from 'ngx-take-until-destroy';
  3.  
  4. @Component({
  5. selector: 'app-step-three',
  6. templateUrl: './step-three.component.html'
  7. })
  8. export class StepThreeComponent implements OnInit, OnDestroy {
  9. form: FormGroup;
  10.  
  11. constructor(
  12. private builder: FormBuilder,
  13. private formsManager: AkitaNgFormsManager<any>
  14. ) { }
  15.  
  16. ngOnInit() {
  17. this.form = this.builder.group({
  18. children: ['', Validators.required],
  19. childrenNames: this.builder.array([])
  20. });
  21.  
  22. const createChildName = () => this.builder.control('', Validators.required);
  23.  
  24. this.formsManager.upsert('stepThree', this.form, {
  25. arrControlFactory: {
  26. childrenNames: createChildName
  27. }
  28. });
  29.  
  30. this.form
  31. .get('children')
  32. .valueChanges.pipe(untilDestroyed(this))
  33. .subscribe(val => {
  34. // Update the number of controls in the form array to match
  35. // the selected number of children
  36. });
  37. }
  38.  
  39. ngOnDestroy() {
  40. this.formsManager.unsubscribe();
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement