• Register
0 votes

Problem :

I am beginner in using Angular material. I am trying to use autocomplete component in the Angular2 project.

Please find below the code written for my component.

import {Component, OnInit} from "@angular/core";
import {ActivatedRoute, Router} from "@angular/router";
import {FormControl} from "@angular/forms";

    mytemplateUrl: './edit_item.component.html',
    mystyleUrls: ['./edit_item.component.scss']
export class MyStateComponent implements OnInit {
    mystateCtrl: FormControl;
    mystates = [....states related data....];

    constructor(private route: ActivatedRoute, private router: Router) {
        this.mystateCtrl = new FormControl();
        this.filteredStates = this.mystateCtrl.valueChanges.startWith(null).map(name => this.filterStates(name));
    ngOnInit(): void {
    filterStates(val: string) {
        return val ? this.mystates.filter((s) => new RegExp(val, 'gi').test(s)) : this.mystates;

But I am facing a below error. I guess my formControl directive is not located.

“Can't bind to 'formControl' since it isn't a known property of 'input'”

I am struggling with this issue from past 2 days but unable to resolve it.

Can somebody help me in fixing this issue?

8 4 2
2,300 points

1 Answer

0 votes

Solution :

I had also faced this issue related to formControl this is very tricky issue and so beginners often find it very difficult to fix it.

When I was using the formControl I had imported ReactiveFormsModule to my imports array as shown below.

import {FormsModule, ReactiveFormsModule} from '@angular/forms';

  imports: [
export class MyStateComponent implements OnInit{}
I hope my solution will save your time and fix your issue.
5 2 1
4,980 points

Related questions

0 votes
1 answer 54 views
Problem : I am facing below error when trying to launch my Angular app, even if my component is not displayed at all. “Can't bind to 'ngmodel' since it isn't a known property of 'input'. ("” How can I fix this issue?
asked Feb 19 mphil 2.3k points
1 vote
2 answers 106 views
Problem : I am beginner to Angular2. Currently I am trying to create a simple form in the Angular2 app but it is not working for me. I am facing below error. “Can't bind to 'formGroup' since it isn't a known property of 'form'.” I am struggling on this error from couple of days. Still I don’t know how to fix above error. Is it possible for somebody to fix it for me?
asked Mar 27 morrisBson 3.2k points
0 votes
1 answer 1K views
Problem: I am beginner to Angular. I have recently started working in Angular project but I am facing below bizarre error: &ldquo;Can't bind to 'ngIf' since it isn't a known property of 'div'.&rdquo; The element is I guess <div [ngIf]="isAuth" id="sidebar ... is the child component. In my parent component i.e. App component the ngif works properly. Please Note: I am currently using Angular RC5.
asked Aug 17 Raphael Pacheco 4.9k points
1 vote
1 answer 99 views
Problem : I am very new to Angular2. Currently I am trying to create the component after that it is set to the root component but still I am facing below error: Template parse errors: Can't bind to 'routerLink' since it isn't a known property of 'a'. I ... days on researching and trying to fix above error but unable to fix it so now I need Angular2 experts advice to quick fix my Angular2 error.
asked May 2 stewart 4k points