angular-forms

Limit input field to two decimal places - Angular 5

本小妞迷上赌 提交于 2019-12-17 11:04:34
问题 The code is as follows <input type="number" class="form-control" value="" name="cost_price" #name="ngModel" [(ngModel)]="item.cost_price" placeholder="Cost Price" /> User should not be able to type more that 2 decimal places. For example, if the user wants to enter 21.256. He should be only allowed to enter 21.25 How to achieve this using angular 5? 回答1: First create Directive for limit the two decimal places in typescript like this: import { Directive, ElementRef, HostListener } from '

Create a reusable FormGroup

淺唱寂寞╮ 提交于 2019-12-17 10:34:38
问题 I am aware of creating custom controls as components, but I can't figure out how to create custom groups . The same we can do this by implementing ControlValueAccessor and using a custom component like <my-cmp formControlName="foo"></my-cmp> , how can we achieve this effect for a group? <my-cmp formGroupName="aGroup"></my-cmp> Two very common use-cases would be (a) separting a long form into steps, each step in a separate component and (b) encapsulating a group of fields which appear across

Confirm password validation in Angular 6

你说的曾经没有我的故事 提交于 2019-12-17 04:59:27
问题 I want to perform password and confirm password validations using material components only,and an error message below the confirm password field if confirm password field doesn't match And if it is empty .Tried many resources unable to achieve. Tried this video too. This is the material component i am looking for HTML <mat-form-field > <input matInput placeholder="New password" [type]="hide ? 'password' : 'text'" [formControl]="passFormControl" required> <mat-icon matSuffix (click)="hide =

Confirm password validation in Angular 6

故事扮演 提交于 2019-12-17 04:57:33
问题 I want to perform password and confirm password validations using material components only,and an error message below the confirm password field if confirm password field doesn't match And if it is empty .Tried many resources unable to achieve. Tried this video too. This is the material component i am looking for HTML <mat-form-field > <input matInput placeholder="New password" [type]="hide ? 'password' : 'text'" [formControl]="passFormControl" required> <mat-icon matSuffix (click)="hide =

Angular: set selected value for <select>

半腔热情 提交于 2019-12-14 03:47:47
问题 I have data set for my <select> loaded asynchronously. I use hot observable, as the data can change in time. The problem is I am unable to set selected value and also Angular does not point to first element by itself (there is no value set until user does it). I'm trying to subscribe to my own observable and... it doesn't work, I wonder why? How can I solve this problem? PLNKR: https://plnkr.co/edit/uDmTSHq4naYGUjjhEe5Q @Component({ selector: 'my-app', template: ` <div> <h2>Hello {{name}}</h2

Allow Input Quantity Based On Available Quantity in Reactive Forms

走远了吗. 提交于 2019-12-14 03:08:49
问题 I need help in my problem since i need to input only the quantity based on the available quantity on my rows? How can i only submit the button if this requirement is met? How can i check for this? Here's the link LINK CODES initGroup() { let rows = this.addForm.get('rows') as FormArray; rows.push(this.fb.group({ ingredient_id: ['', Validators.required], qty_available: new FormControl({ value: '', disabled: true }, Validators.required), qty: ['', Validators.required] })) } 回答1: //when push the

Can't bind to 'x' since it isn't a known property of 'input' Angular 2

你。 提交于 2019-12-14 00:37:14
问题 Using Angular 2, having problem to bind regular property to telephone input. The problem is below: Error: Template parse errors: Can't bind to 'textMask' since it isn't a known property of 'input'. ("lass="form-control" name="phone" id="phone" placeholder="Phone" [(ngModel)]="stepModel.phoneNumber" [ERROR ->][textMask]="{mask: mask}" #phone="ngModel"> <input type="email" class="form-cont"): AdvancedReviewStepEarn@14:139 Here the input: <input type="tel" class="form-control" name="phone" id=

Pushing Iterated Rows Depending on Number Selected in Reactive Forms in Angular

扶醉桌前 提交于 2019-12-13 15:46:16
问题 I've a problem in iterating rows when i selecting a number in my dropdown. How would i push that number so that rows(cards) would be iterated depending on that number. My process is this, first you have to select Solo Traveller as 'No' so that the adults and children dropdowns would appear. That dropdown is my problem, how would i iterate rows(cards) depending on that number selected? I've made the rows(cards) but i don't know how would i iterate it. here's my stackblitz link CLICK THIS LINK

What would be the best way to create a form onthe Fly in angular x (2 4 5) and submit it?

女生的网名这么多〃 提交于 2019-12-13 09:09:34
问题 I have an angular x(2 4 5) app, and i must make a post redirect to a bank page, so the user can pay something. So, I want to create a form on the fly in my DOM and post it. Can't find the best way. It's easy to loop and create a form, but not easy to directly post it after drawing it. thanks in advance 回答1: As @DeborahK mentioned, you probably can't directly post an Angular form. However, there's no reason that you can't get the data from the form, and pass it to a service that uses the

why is custom validator not working

淺唱寂寞╮ 提交于 2019-12-13 03:34:34
问题 I created a custom Validator called threeNumbers what it does is that it accepts only three digit numbers. But when I applied it to the username field it throws an error ERROR TypeError: Cannot read property 'length' of null and formGroup expects a FormGroup instance. Please pass one in. ngOnInit() { // form controls validation specicified in the class for the Reactive Forms this.courseForm = this.fb.group({ username: [null, [Validators.required, this.threeNumbers.bind(this)]], email: [null,