Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import {Product} from './model/app.product';
- import {ProductWeightCategory} from './model/productweightcategory';
- import {Component, OnInit} from '@angular/core';
- import {FormGroup, FormControl, Validators, ReactiveFormsModule, FormBuilder} from '@angular/forms';
- import {BsModalRef, BsModalService} from 'ngx-bootstrap';
- @Component({
- selector: 'app-root',
- template: `
- <form class="container col-md-2" [formGroup]="form" (ngSubmit)="onSubmit(form.value)">
- <div>
- <label for="productName">Nazwa produktu</label>
- <input class="form-control" id="productName" type="text" placeholder="" formControlName="productName">
- <span class="small help-block"></span>
- <div *ngIf="productName.touched && productName.invalid" class="alert alert-danger">
- <div *ngIf="productName.errors.minlength ">Nazwa produktu nie może zawierać mniej niż {{productName.errors.minlength.requiredLength}} znaki</div>
- <div *ngIf="productName.errors.maxlength ">Nazwa produktu nie może zawierać wiecej niż {{productName.errors.maxlength.requiredLength}} znaków</div>
- <div *ngIf="productName.errors.required">Pole wymagane</div>
- </div>
- <label for="radios">Kategoria wagowa</label>
- <fieldset formGroupName="productWeightCategory">
- <!!=*==>
- <label>
- <input [value]="element" type="radio" name="categories" [checked]="ind===0" >
- {{element.categoryWeightName}}
- </label>
- </div>
- </fieldset >
- </div>
- <input class="btn btn-primary" type="submit" [disabled]="!form.valid" value="Dodaj">
- </form>
- `,
- styleUrls: ['./app.component.css']
- })
- export class AppComponent implements OnInit {
- form;
- selectedEntry;
- constructor(fb: FormBuilder) {
- this.form = fb.group({
- productName: ['ASD'],
- productWeightCategory: fb.group({
- id: [],
- categoryWeightName: []
- })
- });
- }
- ngOnInit() {
- }
- onSubmit(form) {
- console.log(this.form);
- console.log(JSON.stringify(form));
- }
- get productName() {
- return this.form.get('productName');
- }
- get productWeightCategory() {
- return [new ProductWeightCategory(1, 'asd1'), new ProductWeightCategory(2, 'asd2'), new ProductWeightCategory(3, 'asd3')];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment