Guest User

Untitled

a guest
Dec 27th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import {Product} from './model/app.product';
  2. import {ProductWeightCategory} from './model/productweightcategory';
  3. import {Component, OnInit} from '@angular/core';
  4. import {FormGroup, FormControl, Validators, ReactiveFormsModule, FormBuilder} from '@angular/forms';
  5. import {BsModalRef, BsModalService} from 'ngx-bootstrap';
  6.  
  7. @Component({
  8.   selector: 'app-root',
  9.   template: `
  10. <form class="container col-md-2" [formGroup]="form" (ngSubmit)="onSubmit(form.value)">
  11.  
  12. <div>
  13. <label for="productName">Nazwa produktu</label>
  14. <input class="form-control" id="productName" type="text" placeholder="" formControlName="productName">
  15. <span class="small help-block"></span>
  16. <div *ngIf="productName.touched && productName.invalid" class="alert alert-danger">
  17.   <div *ngIf="productName.errors.minlength ">Nazwa produktu nie może zawierać mniej niż {{productName.errors.minlength.requiredLength}} znaki</div>
  18.   <div *ngIf="productName.errors.maxlength ">Nazwa produktu nie może zawierać wiecej niż {{productName.errors.maxlength.requiredLength}} znaków</div>
  19.   <div *ngIf="productName.errors.required">Pole wymagane</div>
  20. </div>
  21.  
  22.   <label for="radios">Kategoria wagowa</label>
  23.   <fieldset  formGroupName="productWeightCategory">
  24.   <!!=*==>
  25.     <label>
  26.       <input  [value]="element" type="radio" name="categories" [checked]="ind===0" >
  27.       {{element.categoryWeightName}}
  28.     </label>
  29.   </div>
  30.   </fieldset >
  31. </div>  
  32. <input class="btn btn-primary" type="submit" [disabled]="!form.valid" value="Dodaj">
  33. </form>
  34. `,
  35.   styleUrls: ['./app.component.css']
  36. })
  37.  
  38. export class AppComponent implements OnInit {
  39.   form;
  40.    selectedEntry;
  41.  
  42.   constructor(fb: FormBuilder) {
  43.     this.form = fb.group({
  44.       productName: ['ASD'],
  45.       productWeightCategory: fb.group({
  46.         id: [],
  47.         categoryWeightName: []
  48.       })
  49.  
  50.     });
  51.  
  52.   }
  53.   ngOnInit() {
  54.   }
  55.   onSubmit(form) {
  56.    
  57.     console.log(this.form);
  58.     console.log(JSON.stringify(form));
  59.   }
  60.   get productName() {
  61.     return this.form.get('productName');
  62.   }
  63.  
  64.   get productWeightCategory() {
  65.     return [new ProductWeightCategory(1, 'asd1'), new ProductWeightCategory(2, 'asd2'), new ProductWeightCategory(3, 'asd3')];
  66.   }
  67.  
  68. }
Advertisement
Add Comment
Please, Sign In to add comment