patterntypescriptangularCritical
Can't bind to 'formControl' since it isn't a known property of 'input' - Angular2 Material Autocomplete issue
Viewed 0 times
bindpropertyknowninputisnautocompleteangular2sincematerialformcontrol
Problem
I am trying to use Angular Material Autocomplete component in my Angular 2 project. I added the following to my template.
Following is my component.
I'm getting the following error. It looks like the
Can't bind to 'formControl' since it isn't a known property of 'input'
What is the issue here?
{{ state }}
Following is my component.
import {Component, OnInit} from "@angular/core";
import {ActivatedRoute, Router} from "@angular/router";
import {FormControl} from "@angular/forms";
@Component({
templateUrl: './edit_item.component.html',
styleUrls: ['./edit_item.component.scss']
})
export class EditItemComponent implements OnInit {
stateCtrl: FormControl;
states = [....some data....];
constructor(private route: ActivatedRoute, private router: Router) {
this.stateCtrl = new FormControl();
this.filteredStates = this.stateCtrl.valueChanges.startWith(null).map(name => this.filterStates(name));
}
ngOnInit(): void {
}
filterStates(val: string) {
return val ? this.states.filter((s) => new RegExp(val, 'gi').test(s)) : this.states;
}
}I'm getting the following error. It looks like the
formControl directive is not being found.Can't bind to 'formControl' since it isn't a known property of 'input'
What is the issue here?
Solution
While using
Example:
formControl, you have to import ReactiveFormsModule to your imports array.Example:
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
@NgModule({
imports: [
BrowserModule,
FormsModule,
ReactiveFormsModule,
MaterialModule,
],
...
})
export class AppModule {}Code Snippets
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
@NgModule({
imports: [
BrowserModule,
FormsModule,
ReactiveFormsModule,
MaterialModule,
],
...
})
export class AppModule {}Context
Stack Overflow Q#43220348, score: 1147
Revisions (0)
No revisions yet.