Angular2 Reactive forms – Set default value for form fields with dropdown

I know this is an old question, but if anyone looks for it, there is now a better way to set value in the whole form, with PatchValue: this.myForm.patchValue({ country: this.CountryResponse, name: ‘Any Name’ }); this also allows partial, so you would still be able to do something like: this.myForm.patchValue({ country: this.CountryResponse }); or you … Read more

TypeError: Cannot create property ‘validator’ on string ‘abc@gmail.com’ at setUpControl

<form [formGroup]=”form” (ngSubmit)=”onSubmit(form.value)” class=”form-horizontal”> <div class=”form-group row”> <label for=”inputEmail3″ class=”col-sm-4 “>Username</label> <div class=”col-sm-8″> <input formControlName=”email” type=”text” class=”form-control” id=”inputEmail3″ placeholder=”Email Address” [readonly]=”isReadOnly”> </div> </div> </form> please try like this change [formControl] to formControlName. And to set the output to the input field please do the following, point the line this.form.patchValue import { Component } from ‘@angular/core’; … Read more

Angular2 update form control value

In Angular 2 Final (RC5+) there are new APIs for updating form values. The patchValue() API method supports partial form updates, where we only need to specify some of the fields: this.form.patchValue({id: selected.id}) There is also the setValue() API method that needs an object with all the form fields. If there is a field missing, … Read more

Angular 2: Form containing child component

This behavior is expected. Angular forms are not automatically registered when inside nested component. However you can workaround this by providing the outer FormGroup to the child component. And inside the child component wrap the template inside that same group. Here is how this might look: /outer component code – it contains the form/ @Component({ … Read more

How to upload file in Angular2

In fact, the Http class doesn’t support that at the moment. You need to leverage the underlying XHR object to do that: import {Injectable} from ‘angular2/core’; import {Observable} from ‘rxjs/Rx’; @Injectable() export class UploadService { constructor () { this.progress$ = Observable.create(observer => { this.progressObserver = observer }).share(); } private makeFileRequest (url: string, params: string[], files: … Read more

Radio button for boolean property

In the new forms module this might do what you want <input type=”radio” name=”food” [(ngModel)]=”document.valid” [value]=”true”> <input type=”radio” name=”food” [(ngModel)]=”document.valid” [value]=”false”> see also design doc for the new forms module

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)