Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular Forms: "No value accessor for ..."

Using the AngularDart Material package. Could really use some help on this error:

"No value accessor for (username) or you may be missing formDirectives in your directives list."

Minimal setup (formDirectives is specified in directives list):

login.html

<form (ngSubmit)="onSubmit()" #form="ngForm">
        <material-input class="username" ngControl="username" [(ngModel)]="username"
            [required]="true"
            [floatingLabel]="true"
            label="Username">
        </material-input>
</form>

login.dart

import 'package:angular/angular.dart';
import 'package:angular_components/angular_components.dart';
import 'package:angular_forms/angular_forms.dart';

@Component(
  selector: 'login',
  styleUrls: const ['style.css'],
  templateUrl: 'login.html',
  directives: const [formDirectives,MaterialInputComponent,]
)
class LoginComponent {

  String username;
  void onSubmit() {}
}
like image 427
Simon Rubin Avatar asked Dec 17 '22 22:12

Simon Rubin


1 Answers

You need the ControlValueAccessor for material-input in your directives list.

Better to use materialInputDirectives instead of MaterialInputComponent directly as it has the other directives you might want to use to interact with the value.

like image 153
Ted Sander Avatar answered Dec 28 '22 11:12

Ted Sander