ngModel is throwing exceptions, this worked fine in rc4
<input [(ngModel)]="par.name" placeholder="name" />
These are the exceptions:
[email protected]?main=browser:260 Uncaught EXCEPTION: Error in ./CommunityListComponent class CommunityListComponent - inline template:10:27 ORIGINAL EXCEPTION: No value accessor for form control with unspecified name ORIGINAL STACKTRACE: Error: No value accessor for form control with unspecified name
This directive is used by itself or as part of a larger form. Use the ngModel selector to activate it. It accepts a domain model as an optional Input . If you have a one-way binding to ngModel with [] syntax, changing the domain model's value in the component class sets the value in the view.
The ngModel directive is a directive that is used to bind the values of the HTML controls (input, select, and textarea) or any custom form controls, and stores the required user value in a variable and we can use that variable whenever we require that value.
checkDirty(value) { if (value. dirty) { ... } }
If we use two way binding syntax for ngModel the value will be updated. So the default (ngModelChange) function will update the value of ngModel property. i.e., user.Name . And the second (ngModelChange) will be triggered printing the user name value in the console.
can also solve by importing FormsModule into your bootstrap module, then it will be available to all components.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { AppComponent } from 'app/components/app';
@NgModule({
imports: [BrowserModule, FormsModule],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule { }
Now you need to set the name on input. For example;
<input [(ngModel)]="par.name" **name="name"** placeholder="name" />
And all directive must be set on *.module.ts.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With