Questions tagged [angular2-forms]

An Angular form is a collection of data input controls. Use this tag for questions pertaining to template-driven and reactive forms including NgForm, FormGroup, FormControl, AbstractControl, FormBuilder, and Validators as well as data binding between forms and components.

2655 questions
982
votes
35 answers

Can't bind to 'formGroup' since it isn't a known property of 'form'

THE SITUATION: Please help! I am trying to make what should be a very simple form in my Angular2 app but no matter what it never works. ANGULAR VERSION: Angular 2.0.0 Rc5 THE ERROR: Can't bind to 'formGroup' since it isn't a known property of…
FrancescoMussi
  • 17,011
  • 36
  • 113
  • 166
263
votes
6 answers

tslint / codelyzer / ng lint error: "for (... in ...) statements must be filtered with an if statement"

Lint error message: src/app/detail/edit/edit.component.ts[111, 5]: for (... in ...) statements must be filtered with an if statement Code snippet (It is a working code. It is also available at angular.io form validation section): for (const…
choopage - Jek Bao
  • 4,915
  • 5
  • 29
  • 59
252
votes
25 answers

TypeScript-'s Angular Framework Error - "There is no directive with exportAs set to ngForm"

I keep getting this error while using TypeScript's Angular2-forms framework: There is no directive with "exportAs" set to "ngForm" Here's my code project dependencies : "dependencies": { "@angular/common": "2.0.0-rc.6", …
Nassim MOUALEK
  • 4,180
  • 3
  • 20
  • 38
251
votes
9 answers

How can I manually set an Angular form field as invalid?

I am working on a login form and if the user enters invalid credentials we want to mark both the email and password fields as invalid and display a message that says the login failed. How do I go about setting these fields to be invalid from an…
efarley
  • 6,781
  • 8
  • 36
  • 61
183
votes
14 answers

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

I'm trying to implement Dynamic Forms in Angular 2. I've added additional functionalities like Delete and Cancel to the dynamic forms. I've followed this documentation: https://angular.io/docs/ts/latest/cookbook/dynamic-form.html I've made some…
Varun
  • 3,355
  • 4
  • 18
  • 33
174
votes
6 answers

What are the practical differences between template-driven and reactive forms?

I have been reading about Angular2 new Forms API and it seems that there are two approaches on forms, one is Template driven forms other is reactive or model-driven forms. I would like to know the practical difference between the two, not the…
gdyrrahitis
  • 4,340
  • 3
  • 20
  • 36
140
votes
4 answers

Angular 2 disabled controls do not get included in the form.value

I have noticed that if I disable a control on an Angular 2 reactive form then the control does not get included in the form.value. For example, if I define my form like below: this.notelinkingForm = new FormGroup({ Enabled: new…
Jim Culverwell
  • 2,113
  • 6
  • 20
  • 27
125
votes
15 answers

Apply a directive conditionally

I am using Material 2 to add md-raised-button. I want to apply this directive only if certain condition becomes true. For example: Another example: I created a basic dynamic reactive form in plunker. I am…
121
votes
10 answers

The pipe ' ' could not be found angular2 custom pipe

I can't seem to fix this error. I have a search bar and an ngFor. I am trying to filter the array using a custom pipe like this: import { Pipe, PipeTransform } from '@angular/core'; import { User } from '../user/user'; @Pipe({ name:…
Sumama Waheed
  • 3,419
  • 3
  • 16
  • 32
120
votes
13 answers

Angular ReactiveForms: Producing an array of checkbox values?

Given a list of checkboxes bound to the same formControlName, how can I produce an array of checkbox values bound to the formControl, rather than simply true/false? Example:
ReactingToAngularVues
  • 8,053
  • 20
  • 73
  • 137
119
votes
10 answers

Angular2 disable button

I know that in angular2 I can disable a button with the [disable] attribute, for example: but can I do it using [ngClass] or [ngStyle] ? Like so:
118
votes
11 answers

Angular2 Error: There is no directive with "exportAs" set to "ngForm"

i'm on the RC4 and i'm getting the error There is no directive with "exportAs" set to "ngForm" because of my template :