angular4-forms

Checking Multiple Row Custom Validator in Angular 4 Reactive Forms

[亡魂溺海] 提交于 2019-12-30 14:48:30
问题 I have a very simple problem which I can't get it. First, I have an ingredient which has an approved quantity. And that ingredient has several expiration dates. However, I want to check if my expiration dates which has the "quantity to transfer" is not more than the approved quantity. How should I check this? I already finished some parts BUT this one I couldn't compare since it has to check several rows of "quantity to transfer" against the one approved quantity. Here's the code link below:

Angular4 - No value accessor for form control

十年热恋 提交于 2019-12-27 13:03:28
问题 I have a custom element : <div formControlName="surveyType"> <div *ngFor="let type of surveyTypes" (click)="onSelectType(type)" [class.selected]="type === selectedType"> <md-icon>{{ type.icon }}</md-icon> <span>{{ type.description }}</span> </div> </div> When I try to add the formControlName, I get an error message: ERROR Error: No value accessor for form control with name: 'surveyType' I tried to add ngDefaultControl without success. It seems it's because there is no input/select... and I

Toggle button based on json response in angular 2

风格不统一 提交于 2019-12-25 18:14:35
问题 I am trying to toggle button based on backend response.If the response is Yes, toggle button should be ON, if the response is No, toggle button should be off. Below is my html code <div class="btn-group btn-toggle"> <button class="btn btn-sm btn-default">ON</button> <button class="btn btn-sm btn-primary ">OFF</button> </div> Below is my component code, where i calling a get service which returns response either Yes or No.I am calling the service in ngOnit() because i want to check whether the

Angular 7 Form Validation and Display error message

旧街凉风 提交于 2019-12-24 11:16:08
问题 Please look my simple form in Stackblitz https://stackblitz.com/edit/angular-et9uww My form contains 2 checkboxes if I select one of the checkboxes it will populate one textbox. In my scenario, I have 2 checkboxes and 2 text boxes and one submit button. NOTE- in my case i have n number of checkbox and child questions Validation includes -> 2 textbox are mandatory If the user submits the form without entering textbox it will show the error message. STEP to Recreate check the checkbox1, textbox

Unable to hide error msg in angular 4

邮差的信 提交于 2019-12-24 08:48:50
问题 If there is no data i want to show some message. I have written the logic for that and it works. But if there is some data then also its showing the same message. No idea why its not working properly. Help will be much appreciated. Logic in my typescript component validation: boolean; constructor( ) { this.validation = false; } searchEmployee(name: string): void { var config = { headers: { 'Content-Type': 'application/json' } }; const empName = name; let obj = { empNamewers: empName } let

validate email on angular 4

早过忘川 提交于 2019-12-24 01:59:16
问题 i'm new to reactive form in angular 4. how do i put a pattern validation in email? i'm confused with https://angular.io/api/forms/EmailValidator app.component.htmlapp.component.tsmodal 回答1: If you need mail validator, you can use my code: export class GlobalValidator { static mailFormat(control: FormControl) { const EMAIL_REGEXP = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; if

Angular 2 / 4 : How to POST HTML form (Not ajax) thru component on callback of 1st ajax submit?

早过忘川 提交于 2019-12-21 11:46:05
问题 I want to submit form to external site by POSTing the input fields in old school way(non Ajax) , it submits too but Angular giving me error in console before jumping to external page. I used following code in HTML(template) <form (submit)="onSubmit($event)" method="POST" [formGroup]="form" *ngIf='form' action="https://www.sandbox.paypal.com/cgi-bin/webscr" > In component onSubmit(obj: any) { if (!this.form.valid) { this.helper.makeFieldsDirtyAndTouched(this.form); } else { this.loader = true;

How to set ngIf dynamic condition in dynamic form in angular 4

て烟熏妆下的殇ゞ 提交于 2019-12-21 06:37:26
问题 I am creating a dynamic form where I am populating the fields dynamically based on the response from JSON like. Eg:- [{ "type":"text", "required":true, "minlength": 3, "maxlength":5, "name":"fname", "visibility":true }, { "type":"text", "required":true, "minlength": 3, "maxlength":5, "name":"lname", "visibility":"fname == 'abc' || fname == 'xyz'" }, { "type":"text", "required":true, "minlength": 3, "maxlength":5, "name":"fid", "visibility":true }, { "type":"text", "required":true, "minlength"

How to set first option as selected where options build from loop in select box anular 4

ⅰ亾dé卋堺 提交于 2019-12-20 05:57:21
问题 I have worked on angular 4 project, In this project, I have a requirement to set the first option as selected where all options are created dynamically by loop. html code: <select [(ngModel)]="selectedServiceType" [ngModelOptions]="{standalone: true}" (ngModelChange)="getServiceType($event)"> <ng-container *ngFor="let service of services"> <option [ngValue]="service">{{service.name}}</option> </ng-container> </select> If anyone know about let me know. Thanks in advance! 回答1: Try like this :

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