TypeScript-‘s Angular Framework Error – “There is no directive with exportAs set to ngForm”
import { FormsModule } from ‘@angular/forms’; @NgModule({ imports: [ BrowserModule, FormsModule //<———-make sure you have added this. ], …. })
import { FormsModule } from ‘@angular/forms’; @NgModule({ imports: [ BrowserModule, FormsModule //<———-make sure you have added this. ], …. })
Here’s how it currently works with Angular 4.1.0 – 5.1.3: class YourComponent { @ViewChild(“yourForm”) yourForm: NgForm; onSubmit(): void { doYourThing(); // yourForm.reset(), yourForm.resetForm() don’t work, but this does: this.yourForm.form.markAsPristine(); this.yourForm.form.markAsUntouched(); this.yourForm.form.updateValueAndValidity(); } }
I believe you missed an important point: [formGroup] directive in the second example. formControlName is used together with [formGroup] to save your form multiple dot navigations. For example: <div> <input type=”text” [formControl]=”myForm.controls.firstName”/> <input type=”text” [formControl]=”myForm.controls.lastName”/> <input type=”text” [formControl]=”myForm.controls.email”/> <input type=”text” [formControl]=”myForm.controls.title”/> </div> Is equivalent to: <div [formGroup]=”myForm”> <input type=”text” formControlName=”firstName”/> <input type=”text” formControlName=”lastName”/> <input type=”text” … Read more
I fixed it using kemsky answer and Sebastien’s comment. I made a ngValueAccessor which registers itself on every input with type file. Plunkr can be found here. Most relevant code + explanation beneath: This adds a ControlValueAccessor for file inputs which might be part of the angular framework itself someday(#7341). A file input works different … Read more
Here’s a shortened version of your code: When you init your form, you can add one empty formgroup inside your formArray: ngOnInit() { this.invoiceForm = this._fb.group({ itemRows: this._fb.array([this.initItemRows()]) }); } get formArr() { return this.invoiceForm.get(‘itemRows’) as FormArray; } Then the function: initItemRows() { return this._fb.group({ // list all your form controls here, which belongs to … Read more
Make sure you are not facing a “cross module” problem If the component which is using the pipe, doesn’t belong to the module which has declared the pipe component “globally” then the pipe is not found and you get this error message. In my case I’ve declared the pipe in a separate module and imported … Read more
I know this is an old question, but this is one of the first places I landed when searching for this functionality so I’ll add how I was able to solve it. ngContent is only for static projection, so you can’t use it to do any bindings. If you need bindings in your projected content … Read more
The code below does not work with pure ngModel binding, so I did a lot of experiments. Latest, also confirmed by Maximillian Schwarzmuller should be the one: @Directive({ selector: ‘[ngModel], [formControl]’, // or ‘input, select, textarea’ – but then your controls won’t be handled and also checking for undefined would be necessary }) export class … Read more
There are a few issues in your code <div [formGroup]=”form”> outside of a <form> tag <form [formGroup]=”form”> but the name of the property containing the FormGroup is loginForm therefore it should be <form [formGroup]=”loginForm”> [formControlName]=”dob” which passes the value of the property dob which doesn’t exist. What you need is to pass the string dob … Read more
You can do only using html: <md-input-container class=”md-icon-float md-block” flex-gt-sm> <label>Email</label> <input md-input id=”contact-email” type=”text” ngControl=”email” #email=”ngForm” [(ngModel)]=”contact.email” required pattern=”^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,6})+$”> <div class=”md-errors-spacer” [hidden]=”email.valid || email.untouched”> <div class=”md-char-counter” *ngIf=”email.errors && email.errors.required”> Email is required </div> <div class=”md-char-counter” *ngIf=”email.errors && email.errors.pattern”> Email is invalid </div> </div> </md-input-container>