angular2-forms

Template driven form validation in parent component with ng-content

断了今生、忘了曾经 提交于 2019-12-10 23:03:16
问题 I've been searching for the answers for past days, but I cannot find a solution. I have a base page component and all others pages extend it because lots of crud pages are involved. In my scenario, I created a modal and a ng-content selector to be fullfilled with inputs when I need it. Codes: base-page-list.component.html <section class="widget animated fadeIn" widget> <header> <h4 class="page-title" *ngIf="pageType !== PageType.TAB"> <ng-content select=".page-title"></ng-content> </h4> <div

How to show md-error message for dynamic form array?

冷暖自知 提交于 2019-12-10 22:18:23
问题 I have a dynamic form array, If i click add contact button it will add dynamic form field after that i tried to validate the form fields(validator.required, validator.pattern etc..) and its working fine. When i tried to show below error message in html view <md-error *ngIf="myForm.controls.myContactArray.controls['name'].hasError('required')"> Email is <strong>required</strong> </md-error> getting below error message core.es5.js:1020 ERROR TypeError: Cannot read property 'hasError' of

Dynamically adding required to input in template driven angular 2 form

邮差的信 提交于 2019-12-10 21:47:22
问题 Template driven approach: Dynamically adding required attribute to input filed in angular 2 form. But the angular form validation(form.valid) not recognizing the dynamically added required field. <input type="text" [(ngModel)]="coumnName" name="coumnName" > Adding dynamically required: document.getElementsByName(columnName)[0].setAttribute('required', ''); 回答1: You can use the same technique as setting a validator dynamically for a FormControl in a reactive form, but using the NgForm

Angular2 No provider for Renderer! (NgModel -> Token NgValueAccessor -> DefaultValueAccessor -> Renderer)

£可爱£侵袭症+ 提交于 2019-12-10 20:49:13
问题 I custom modal of customModal.ts in shlomiassaf/angular2-modal. Specific, i add a input contain ngModel, it imported FORM_DIRECTIVES and directives. The issue when run 'No provider for Renderer! (NgModel -> Token NgValueAccessor -> DefaultValueAccessor -> Renderer)' Please help me resovle this issue. Thanks. 回答1: I see two possibilities: The corresponding provider isn't specified at the component or application level. I don't think that the problem because I already inject a Renderer without

Angular2 and disabling button exception

柔情痞子 提交于 2019-12-10 19:37:10
问题 In my code I have button, that is disabled whenever the form is invalid, or not dirty. I have: <button type="submit" [disabled]="!myForm.valid || myForm.dirty" class="save-button">Save</button> Which throws me EXCEPTION: Expression '!myForm.valid || myForm.dirty) in MyFromComponent@58:38' has changed after it was checked. Previous value: 'true'. Current value: 'false' in [!myForm.valid || myForm.dirty in MyFromComponent@58:38] Whenever the validity/dirty changes. Any ideas? UPDATE It works

Setting initial value Angular 2 reactive formarray

ⅰ亾dé卋堺 提交于 2019-12-10 18:17:31
问题 I am trying to set the initial value for an angular 2 reactive form formArray object. Even though the json object used to set the form value contains an array value with multiple entries, only the first entry is shown and the "form.value" also only shows the first entry. I am using the syntax (<FormGroup>this.myForm).patchValue(value, { onlySelf: true }); to set the initial value on the form. Here is a plunker demonstrating the issue: https://plnkr.co/edit/j1S80CmPBF1iHI5ViEia?p=preview I

Skip programmatic changes in valueChanges of Angular 2 control

守給你的承諾、 提交于 2019-12-10 17:12:03
问题 I'm subscribing to the valueChanges observable of an Angular 2 (2.2.1) control. It's defined in AbstractControl in @angular\forms\src\model.d.ts and it's doc string states that it will yiald changes from the UI as well as programmatic ones: /** * Emits an event every time the value of the control changes, in * the UI or programmatically. */ valueChanges: Observable<any>; How can I filter this down to give me only the changes from the UI and not the programmatic ones? I think that the boolean

Angular2 (beta3) “expression has changed after it was checked” in updating form values

杀马特。学长 韩版系。学妹 提交于 2019-12-10 16:46:05
问题 This is a sort of continuation of my previous post about nested forms in Angular2 (beta 3 with TS) (Angular2 beta: nesting form-based parent/child components and validating from parent), but I'm posting a new question as it refers to a different type of issue. You can find the repro of the issue described here at http://plnkr.co/edit/iCmmy9at2wF5qY0P6VmV. In short, in this fake scenario I have a component representing a single word from an imaginary dictionary, and another child component

Angular binding object with array from component to view with ngModels

为君一笑 提交于 2019-12-10 12:58:46
问题 I tried to bind my model on my view, but I have a problem when I submit my form : I don't have an array, but many property. component : export class QuizFormAddQuestionComponent implements OnInit { public question: Question; constructor() { this.question = new Question(); } ngOnInit() { this.question.setModel({ question: 'test' }); this.question.setAnswers(3); } createQuestion(form) { console.log(form.value); } } my template : <hello name="{{ name }}"></hello> <div class="row"> <div class=

populate values in Form control from nested Form Array from JSON data

青春壹個敷衍的年華 提交于 2019-12-10 12:05:46
问题 FormArrayThe formObj has array of componentDetails Object which in turn has a nested array of component array. export class FormViewComponent implements OnInit { public callbackForm: FormGroup; formObj = { "componentDetails": [{ "component": [{ "value": "Choice 1" }, { "value": "Choice 2" }], "cpv": "", "label": "Description of Problem", "type": "radio", "mandatory": true }] }; loadObservableForm() { this.formService.getData(this.id) .subscribe( (formObj) => { this.formObj = formObj; this