angular4-forms

Angular 4 Dynamic component loading & emitting data to parent component

折月煮酒 提交于 2019-12-08 03:20:22
问题 I am on process of creating poc for dynamic form generation using custom components. i have succeeded upto some extent, where i can create form using set of dynamic components according to a json array. Now i am stuck in one instance where i just need to get output or rather the data out of these components ones the user have update the relevant inputs. I had a look at the @output decorator and the eventEmitter yet i couldn't get a proper solution out of it. Much appreciate if any one in the

How to disable previous date in ngbDatepicker in Angular 4?

半城伤御伤魂 提交于 2019-12-08 02:39:40
问题 I want to disable all the previous/past date in ngbDatepicker , I have used ngbDatepicker . My HTML is: <input required class="form-control" placeholder="dd-MM-YYYY" name="startDate" required ngbDatepicker #d="ngbDatepicker" [readonly]="true" [formControl]="formModel.controls.startDate" [ngClass]="{'has-error':!formModel.controls['startDate'].valid && formModel.controls['startDate'].touched}" /> 回答1: You could create an Implementation of NgbDatepickerConfig specifying when starts and ends

Fire validation when focus out from input in angular?

北城以北 提交于 2019-12-07 16:59:12
问题 Email validation is being fired as we keep typing in textbox. I want this validation to be fired when user focuses out of the textbox Below is my code: <input class="form-control" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$" name="Email" type="email" [(ngModel)]="model.Email" #Email="ngModel" required> <div class="red" *ngIf="Email.errors && (Email.dirty || Email.touched)"> <div [hidden]="!Email.errors.pattern"> Please enter a valid email. </div> </div> Please suggest me how can I

angular 4 own form element component

放肆的年华 提交于 2019-12-06 14:54:03
I am beginner in angular and I may need a little help with this thing. First of all I will just show how could it work then I will write about how I want it to work. This is the regular way when you work with ngModel: <form> <input name="name" placeholder="name" [(ngModel)]="model.name" value="" /> <select name="select" [(ngModel)]="model.select"> <option value="1">..</option> ... </select> <input type="button" value=" click me" /> </form> This is good enough if you don't want an own appearance for the select. My aim is to create a component for this where I can create divs and other contents

Correct way to integrate reCAPTCHA with Angular 4

寵の児 提交于 2019-12-06 08:08:47
I'm trying to integrate an Invisible reCAPTCHA with my Angular 4 form. In the TS part of the component I have a function like this: onSubmit(token: string) { alert(token); } And my HTML looks like this (only the relevant parts shown): <form (ngSubmit)="onSubmit()" #myForm="ngForm"> <button type="submit" class="btn g-recaptcha" data-sitekey="mykey" data-callback="onSubmit">Submit</button> </form> When clicking on that button I get either an alert saying the token is undefined, or I get an error message like this: "Cannot contact reCAPTCHA. Check your connection and try again." Not really

How to disable previous date in ngbDatepicker in Angular 4?

耗尽温柔 提交于 2019-12-06 07:34:21
I want to disable all the previous/past date in ngbDatepicker , I have used ngbDatepicker . My HTML is: <input required class="form-control" placeholder="dd-MM-YYYY" name="startDate" required ngbDatepicker #d="ngbDatepicker" [readonly]="true" [formControl]="formModel.controls.startDate" [ngClass]="{'has-error':!formModel.controls['startDate'].valid && formModel.controls['startDate'].touched}" /> Sorry for being late. I just came across this question, and the above answer that mutates the properties of NgbDatcConfig . That solution works fine, but it will affect all the other NgbDatepicker

angular material 2 custom component with ng value accessor

烂漫一生 提交于 2019-12-06 03:45:39
问题 I a working on angular 4.4 + material beta12 custom component and not able to figure out what is wrong in my implementation I am trying to achieve the below custom input Task: set value to formControl, once I got data from server(data.productTeam is data-can see in code) on edit, formcontrol should be updated with values (eg:P12DT2H231M) Issues: I am not able to bind default value to formcontrol. Without ngDefaultControl (No value accessor for form control with name: 'productTeam' error

angular - Angular Material 2 Stepper Controls

五迷三道 提交于 2019-12-05 12:23:06
I set up a linear stepper using the Angular Material 2 Stepper. I have forms in different components (component-a, component-b, component-c). In my main container component (container-component) I want to have linear stepper that 'steps' through each component when their form is valid. Is there some sort of functionality to talk up to the stepControl in the stepper to make it properly work? I have attached documentation for the stepper and a StackBlitz version of the application. Also, a link to the repo I have working as well. Material Stepper Component: https://material.angular.io/components

at least one field is required in angular 4 forms

不羁岁月 提交于 2019-12-05 02:38:21
问题 I'm using angular 4 forms and I have some fields. and first_name, last_name and company are really important for me. I want to force the user to fill one of these 3 fields. how can I do it? here are .ts codes: this.contactForm = this.fb.group({ first_name: [null, Validators.compose([Validators.required])], last_name: [null, Validators.compose([Validators.required])], email: [null, Validators.compose([this.validateEmail])], company: [null], position: [null], }); an html: <form [formGroup]=

How to pass all checked checkbox values on Form Submit in angular 4/6/7

帅比萌擦擦* 提交于 2019-12-04 22:42:40
问题 I want to fetch all checked items of a form in component without using change() or click() function as it is unable to fetch already checked items. Here is my Array in TS: PartyRoles = [ { Id: 1, Name: "Vendor", Checked: true }, { Id: 2, Name: "Client", Checked: true }, { Id: 3, Name: "Consigner", Checked: false } ] My HTML Form: <form (ngSubmit)="editPartyRolesSubmit()"> <div *ngFor="let item of PartyRoles"> <label> <input type="checkbox" value="{{item.Id}}" [attr.checked]="item.Checked=