Advertisement
Guest User

Untitled

a guest
Jan 17th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // profile.component.ts
  2.   ruleList: Array<any>;
  3.   profileForm = new FormGroup({
  4.     firstName: new FormControl(''),
  5.     lastName: new FormControl(''),
  6.     rules: new FormArray([])
  7.   });
  8.   initForm() {
  9.     this.store.select('profile').subscribe(profile => {
  10.       profile.rules.forEach(rule => {
  11.         const ruleList = this.profileForm.get('rules') as FormArray;
  12.         ruleList.push(new FormControl(rule));
  13.       });
  14.     });
  15.  
  16.     this.store.select('profileRules').subscribe(rules => {
  17.       rules.forEach(rule => {
  18.         this.ruleList.push(rule);
  19.       });
  20.     });
  21.   }
  22.  
  23. // profile.component.html
  24. <!!=*==>
  25.   <input type="checkbox" [formControlName]="i"> {{ruleList[i].name}}
  26. </label>
  27. lub
  28. <label formArrayName="rules" *ngFor="let rule of (profileRules$ | async).list; let i = index">
  29.   <input type="checkbox" [formControlName]="i"> {{rule.name}}
  30. </label>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement