Directive [(ngModel)] = no longer works in rc5

ngModel throws exceptions, this works fine in rc4

<input [(ngModel)]="par.name" placeholder="name" /> 

These are exceptions:

zone.js@0.6.12? main = browser: 260 Unclear EXCLUSION: Error in. / CommunityListComponent class CommunityListComponent - built-in template: 10: 27 ORIGINAL EXCLUSION: No access to access forms with an unspecified name ORIGINAL STACKTRACE: Error: no access to data to manage a form with an undefined name

+4
angular
Aug 11 '16 at 2:17
source share
5 answers

can also be solved by importing FormsModule into your bootstrap module, then it will be available for 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 { } 
+7
Aug 11 '16 at 9:58 on
source share

Try it -

 import { Component, OnInit } from '@angular/core'; import { FORM_DIRECTIVES } from '@angular/common'; @Component({ selector: 'my-app', template: `<h1>My First Angular 2 App</h1> <input [(ngModel)]="employee.empName"> `, directives: [FORM_DIRECTIVES] }) export class AppComponent { employee = { empName: 'Sanket', email: '', phone: '', address:'' }; ngOnInit() { } } 

This works for me in RC5.

Link - https://angular.io/docs/ts/latest/api/common/index/NgModel-directive.html

+3
Aug 11 '16 at 4:04 on
source share

Now you need to specify a name in the input. For example:

 <input [(ngModel)]="par.name" **name="name"** placeholder="name" /> 

And all directives should be set to * .module.ts.

+1
Aug 16 '16 at 18:07
source share

Two things you need to do using two-way snapping syntax in forms in RC5.

  • Include FormsModule in your app.module.ts

  • Use the name attribute in the html input tags as follows:

    <input type="text" name="name" [(ngModel)]="par.name" />

What all.

+1
Aug 18 '16 at 19:14
source share

You need to directly say that the changes are made. Note:

  • import {ChangeDetectorRef}
  • declare your object in the constructor.
  • this.object.detectChanges(); in the function in which the changes occur.
0
May 10 '17 at 11:56 a.m.
source share



All Articles