angular-forms

angular 5 populate form fields using other field values if checkbox is selected

落爺英雄遲暮 提交于 2019-12-02 03:47:11
I've got two sections of forms - correspondence address and residential address. The goal is to copy/pass values from one field to another if a checkbox is checked. Kindly see below use case populate the correspondence address fields with the values of the residential address form fields iff a checkbox (same as residential address) is checked Should any form field in the residential address change after checking the checkbox, pass the change(s) realtime to the field in the correspondence address and lastly, clear the form values in the correspondence address if the checkbox is unchecked. Below

mat-datepicker inside *ngFor

元气小坏坏 提交于 2019-12-01 06:04:02
This issue faced when using mat-datepicker inside *ngFor . mat-datepicker requires a template reference variable #test in order to bind to the input . Is there a direct way to take reference variables when using inside *ngFor , in general? I couldn't find a way. Simple working example without *ngFor <mat-form-field> <input matInput [matDatepicker]="test" placeholder="Enter Date" [(ngModel)]="someDate" name="someDate"> <mat-datepicker-toggle matSuffix [for]="test"></mat-datepicker-toggle> <mat-datepicker #test></mat-datepicker> </mat-form-field> But since template reference variables must be

Angular 2 Material input focus not working

风流意气都作罢 提交于 2019-12-01 03:33:30
The inputs are inside of a modal dialog. I have no idea why it is not working. I looked at the official docs and it listed focus as something you can pass to the element but it's not working? Does anyone know why? Angular Material - Input Docs <form class="example-form"> <md-input-container class="example-full-width" style="width: 300px; padding: 5px; border-radius: 10px;"> <input mdInput type="email" name="to" placeholder="Email"> <md-error></md-error> </md-input-container> <md-input-container focus focused> <input mdInput type="text" name="a" placeholder="zzzz" focus focused (focus)=""> </md

mat-datepicker inside *ngFor

早过忘川 提交于 2019-12-01 02:53:05
问题 This issue faced when using mat-datepicker inside *ngFor . mat-datepicker requires a template reference variable #test in order to bind to the input . Is there a direct way to take reference variables when using inside *ngFor , in general? I couldn't find a way. Simple working example without *ngFor <mat-form-field> <input matInput [matDatepicker]="test" placeholder="Enter Date" [(ngModel)]="someDate" name="someDate"> <mat-datepicker-toggle matSuffix [for]="test"></mat-datepicker-toggle> <mat

No provider for ControlContainer - Angular 5

有些话、适合烂在心里 提交于 2019-12-01 02:33:44
I am converting a purchased, third-party template into an Angular 5 app, and just ran into an error. I am very new to Angular 5 (I know AngularJS well however) and don't understand what it's trying to tell me? It seems to be related to a button which shows/hides the top navbar. Error Message (from browser): Error: Template parse errors: No provider for ControlContainer ("imalize-styl-2 btn btn-primary " (click)="toggleNavigation()"><i class="fa fa-bars"></i> </a> [ERROR ->]<form role="search" class="navbar-form-custom" method="post" action="#"> <div class="form-gro"): ng:///AppModule

Pass Angular Reactive FormControls to Children Components

ε祈祈猫儿з 提交于 2019-12-01 01:31:07
问题 I have a parent component where I want to create and store my Reactive Form. There will be multiple Form Group instances in a Form Array. I want to pass the Form Controls from each Form Group to a Child Component but am having trouble figuring out how to do this. Here's a Stackblitz demonstrating what I would like to do. Also, some fields will only apply to certain 'makes' of cars which is why i have the following line in my html: <input type="text" *ngIf="car.make != 'ford'" formControlName=

How to access multiple checkbox values in Angular 4/5

三世轮回 提交于 2019-11-30 19:44:25
I want to get the values from my checkboxes but I can only get true or false. Here is my template: <h4>Categories</h4> <div class="form-check" *ngFor="let cat of categories$|async"> <input class="form-check-input" [(ngModel)]="cat.id" name="{{ cat.name }}" type="checkbox" id="{{cat.name}}"> <label class="form-check-label" for="{{cat.name}}"> {{cat.name}} </label> </div> Here is my component this.categories$ = this.storeService.getAllCategories().pipe( map(result => (result as any).data), tap(r => console.log(r)) ) My component basically gets a list of the categories from an external api You

Cannot find control with name: formControlName in angular 2 or 4

淺唱寂寞╮ 提交于 2019-11-30 11:55:37
问题 I found this problem in many questions in stackoverflow but no luck. Please help me for figuring out what I am doing wrong. In component : ngOnInit() { this.companyCreatForm = this._formBuilder.group({ name: [null, [Validators.required, Validators.minLength(5)]], about: [null, [Validators.required]], businessType: [null, [Validators.required]], address: this._formBuilder.group({ street: [], website: [null, [Validators.required]], mobile: [null, [Validators.required]], email: [null,

Angular - Dynamically add/remove validators

て烟熏妆下的殇ゞ 提交于 2019-11-30 07:09:34
问题 I have a FormGroup defined like below: this.businessFormGroup: this.fb.group({ 'businessType': ['', Validators.required], 'description': ['', Validators.compose([Validators.required, Validators.maxLength(200)])], 'income': [''] }) Now when businessType is Other , I want to remove Validators.required validator from description . And if businessType is not Other , I want to add back the Validators.required . I am using the below code to dynamically add/remove the Validators.required . However,

angular 5 template forms detect change of form validity status

落爺英雄遲暮 提交于 2019-11-30 04:47:20
are reactive forms the way to go in order to have a component that can listen for changes in the validity status of the form it contains and execute some compoment's methods? It is easy to disable the submit button in the template using templateRef like [disabled]="#myForm.invalid" , but this does not involve the component's logic. Looking at template forms' doc I did not find a way Sravan If you want to get only the status and not the value you can use statusChanges : export class Component { @ViewChild('myForm') myForm; this.myForm.statusChanges.subscribe( result => console.log(result) ); }