Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.78 KB | None | 0 0
  1. export class SettingsComponent implements OnInit, OnDestroy {
  2.  
  3. ipRangeForm: FormGroup;
  4.  
  5. constructor(
  6. private formBuilder: FormBuilder, private settingsService: SettingsService
  7. ) {
  8. super(baseService);
  9. }
  10.  
  11. ngOnInit() {
  12. this.ipRangeForm = this.formBuilder.group(
  13. {
  14. ipRanges: this.formBuilder.array([])
  15. }
  16. );
  17.  
  18. const stream = this.settingsService.getSettings();
  19.  
  20. stream.subscribe(val => {
  21. this.ipRestrictionEnabled = val.ipRestrictionEnabled;
  22. for (const i of val.ipRanges) {
  23. console.log(i.startRange, i.endRange);
  24. console.log(this.ipRangeForm);
  25. this.addSpecifiedRange(i.startRange, i.endRange);
  26. this.ipRangeForm.controls['ipRanges'].get('startingRange').setValue(i.startRange); //This doesn't update anything, it actu
  27. }
  28. });
  29. }
  30.  
  31. getPageConfig() {
  32. return {
  33. pageKey: 'settings',
  34. displaySidebar: true,
  35. displayToolbar: true,
  36. backButtonRoute: ''
  37. };
  38. }
  39.  
  40. get ipRangeForms() {
  41. return this.ipRangeForm.get('ipRanges') as FormArray;
  42. }
  43.  
  44. addSpecifiedRange(startRange: string, endRange: string) {
  45. const ipRange = this.formBuilder.group({
  46. startingRange: [startRange],
  47. endingRange: [endRange]
  48. });
  49.  
  50. this.ipRangeForms.push(ipRange);
  51. console.log(this.ipRangeForms.getRawValue());
  52. }
  53.  
  54. }
  55.  
  56. <form [formGroup]="ipRangeForm">
  57. <div formArrayName="ipRanges">
  58. <div *ngFor="let ranges of ipRangeForms.controls; let i=index" [formGroupName]="i">
  59. <div class="row mb-lg">
  60. <div class="col-6">
  61. <mat-card>
  62. <div class="row">
  63. <div class="col-5">
  64.  
  65. <mat-form-field style="width: 100%;">
  66. <label>
  67. <input matInput value="" formControlName="startingRange"> <!-- These Inputs do not update to display the data held inside the form array -->
  68. </label>
  69. </mat-form-field>
  70.  
  71. </div>
  72. <div class="col-5">
  73.  
  74. <mat-form-field style="width: 100%;">
  75. <label>
  76. <input matInput value="" formControlName="endingRange"> <!-- These Inputs do not update to display the data held inside the form array -->
  77. </label>
  78. </mat-form-field>
  79.  
  80. </div>
  81. <div class="col-2 remove-column">
  82. <button swui-core-button (click)="deleteRange(i)" class="mr-sm pd-zero"
  83. color="secondary" buttonStyle="link">
  84. {{ getTranslateKey('remove') | translate }}
  85. </button>
  86. </div>
  87. </div>
  88. </mat-card>
  89. </div>
  90. </div>
  91. </div>
  92. </div>
  93. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement