Bug
I wanted to try out the mdAutocomplete component.
Error: Can't bind to 'formControl' since it isn't a known property of 'input'.
I was trying this example from "Examples tab":
https://material.angular.io/components/component/autocomplete
I just do simple copy and paste to my html and ts file.
I'm using master tree from: https://github.com/angular/material2-builds.git
Have you added ReactiveForm in imports ?
Ok i haven't added ReactiveForm to imports, but anyway i did it [(ngModel)] way.
Yep, this looks like you were just missing the module import. Closing.
I am facing same problem.. what is the solution ?
@param-bnb Probably the import of ReactiveForm as mentioned before.
I am also faced with the same issue even after importing ReactiveFormsModule. Any suggestions?
formControl is a directive from @angular/forms, so it's unlikely Material has anything to do with that error. Are you certain you have the ReactiveFormsModule loaded for that component?
I too am having the same issue. Even after importing Reactive forms. But the error changed slightly, now it reads:
Error: No provider for FormControl!
--housing-address.comonent.ts
...
import { FormControl } from '@angular/forms';
...
export class HousingAddressFormComponent implements OnInit {
...
stateCtrl: FormControl;
filteredStates: any;
...
constructor (
...
) {
this.stateCtrl = new FormControl();
this.filteredStates = this.stateCtrl.valueChanges
.startWith(null)
.map(name => this.filterStates(name));
}
...
filterStates(val: string) {
return val ? this.states.filter(s => new RegExp(`^${val}`, 'gi').test(s))
: this.states;
}
---housing-address.component.html
...
<md-input-container>
<input mdInput placeholder="State" [mdAutocomplete]="auto" [formControl]="stateCtrl">
</md-input-container>
<md-autocomplete #auto="mdAutocomplete">
<md-option *ngFor="let state of filteredStates | async" [value]="state.value">
{{ state.key }}
</md-option>
</md-autocomplete>
...
@daddyschmack Can you reproduce in a plunker?
Hi kara, I found the issue, I had double declarations of the FormControl...
Step 3: Import the component modules
Import the NgModule for each component you want to use:
import {MdButtonModule, MdCheckboxModule} from '@angular/material';
@NgModule({
...
imports: [MdButtonModule, MdCheckboxModule],
...
})
export class PizzaPartyAppModule { }
Alternatively, you can create a separate NgModule that imports all of the Angular Material components that you will use in your application. You can then include this module wherever you'd like to use the components.
import {MdButtonModule, MdCheckboxModule} from '@angular/material';
@NgModule({
imports: [MdButtonModule, MdCheckboxModule],
exports: [MdButtonModule, MdCheckboxModule],
})
export class MyOwnCustomMaterialModule { }
Whichever approach you use, be sure to import the Angular Material modules after Angular's BrowserModule, as the import order matters for NgModules.
That you need ReactiveFormsModule is neither mentioned in https://angular.io/guide/forms nor in https://material.angular.io/components/autocomplete/overview or https://material.angular.io/guide/getting-started 馃槥
you are just facing
Error: Can't bind to 'formControl' since it isn't a known property of 'input'.
and asking google for help. :P
I would like to add that I ran into this bug because of casing - I had used [FormControl] instead of [formControl] - this is why adding the ReactiveFormsModule didn't help :)
Big thanks for ReactiveFormsModule hints - that helped a lot.
I second @MA-Maddin 's comment - this requirement should be highlighted. Everything only seems to mention FormsModule.
Eventually digging around the example code shows it in the autogenerated example-modules.ts:
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
Simple fix to the docs?
import {FormsModule, ReactiveFormsModule} from '@angular/forms'; does not fix in my issue
@dapojaja you need to add ReactiveFormsModule in imports array in @NgModule.
I think, i have the same probleme, someone can help me please ?https://stackoverflow.com/questions/50928851/mat-autocomplete-in-formgroup-customfilter
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
_This action has been performed automatically by a bot._
Most helpful comment
Have you added ReactiveForm in imports ?