zero_coding zero_coding - 1 year ago 74
Dart Question

Class 'NgForm' has no instance getter 'user'

I am trying to build a form based on angular2dart.

The component class:

selector: 'start-app',
directives: const[materialInputDirectives],
styleUrls: const ['login_component.css'],
templateUrl: 'login_component.html')
class LoginComponent {

String scaleImg = 'packages/wp_login/assets/scale.svg';
Login login = new Login();

onSubmit() {


and the template:

<div class="container">
<div class="row">
<div class="image">
<img [src]="scaleImg">
<div class="forms">
<form (ngSubmit)="onSubmit()" #login="ngForm">
<material-input type="text" label="User" [(ngModel)]="login.user"></material-input>
<material-input type="password" label="Password" [(ngModel)]="login.password"></material-input>
<material-input type="text" label="Language" [(ngModel)]="login.language"></material-input>



and I've got ther error:

enter image description here

What am I doing wrong?

Answer Source

creates a template variable login that references the NgForm directive.


fails because login references the #login="ngForm" template variable and the error message is right about that it doesn't have a propertyuser`.

You need to rename either the template variable or the property of your component.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download