Have there been any updates to ngFormControl in @angular/forms version 0.3.0?

I recently updated my Angular application from rc4 to rc5, along with upgrading angular forms from version 0.2.0 to 0.3.0. After the update, I started encountering an error that seems to be related to a change in ngFormControl within forms 0.3.0.

zone.js:461 Unhandled Promise rejection: Template parse errors:
Can't bind to 'ngFormControl' since it isn't a known property of 'input'. ("nput type="text" class="form-control search-input" name="search" placeholder="Search..." [value]="" [ERROR ->][ngFormControl]="searchFormControl">

The error points to a line of code that defines a search box in one of my component templates:

<p [hidden]=hideSearch>
  <input type="text" class="form-control search-input" name="search" placeholder="Search..." [value]="" [ngFormControl]="searchFormControl">
</p>

I have not been able to locate any documentation indicating that this functionality has changed. What is the correct alternative to using ngFormControl now?

Edit: Here is the complete component header.component.ts file for context (FormModule and ReactiveFormModule are imported in app.module.ts)

import { Component, EventEmitter, Input, Output} from '@angular/core';
import { Control } from '@angular/common';
import { OrbitService } from './orbit.service';
import 'rxjs/add/operator/debounceTime';

@Component({
  selector: 'orbit-header',

  template: `
    <div class="top-nav row">
      <h3 class="pull-left">Northmark</h3>
      <div class="col-md-2 col-md-offset10 pull-right">
        <p [hidden]=hideSearch>
        <!-- ng-model = [ngFormController] -->
          <input type="search" class="form-control search-input" name="search" placeholder="Search..." [value]="" [NgFormControl]="searchFormControl">
        </p>
        <p>
          <a class="log-out" (click)="orbitService.deleteCookie('ORBIT_COOKIE')">Log Out</a>
        </p>
      </div>
      <div class="clearfix"></div>
    </div>
  `
})

export class HeaderComponent implements OnInit {

  @Input() private hideSearch: boolean;

  constructor(
    private orbitService: OrbitService) {
    this.searchFormControl = new Control();
  }

  @Output() onSubmit = new EventEmitter<string>();

  ngOnInit() {
    this.searchFormControl.valueChanges
      .debounceTime(500)
      .subscribe(query => this.submit(query));
  }

  submit(query: string) {
    this.onSubmit.emit(query);
  }
}

Answer №1

[ngFormControl]="searchFormControl"

needs to be changed to

[formControl]="searchFormControl"

also remember to import ReactiveFormsModule

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What are the steps to ensure that the submit button remains disabled until all form data is filled out with reactive validation?

Is there a way to prevent a form button from being enabled until all required data is entered in a reactive form? You can find the code for my reactive form here. Additionally, how can I reset a reactive form and clear all data after it has been submitted ...

Automatically update the cart count in the header component in Angular 6 when a product is added to the cart, without the need to

I am working on an E-Commerce application using Angular 6. I am facing an issue with updating the shopping cart count in the header component whenever a product is added or removed from the cart. The cart count only updates when I refresh the page. I have ...

Error when sending Angular 4 GET request with multiple Headers results in a 400 bad request code

I've been attempting to perform a POST request with headers in order to receive a response. The Angular code snippet I'm currently using for this request is shown below: const headers = new HttpHeaders({ 'Content-Type': 't ...

Angular component linked to a dynamic object requiring user confirmation before changing or reverting to the original value

I've been working on getting a simple <select> behavior where the value reverts back if the user cancels the change. I managed to achieve it, but it took me quite a few hours and I'm not entirely satisfied with the implementation as it&apos ...

Error: A problem occurred that was not caught in the promise, please investigate further

@Injectable() class MyErrorHandler implements ErrorHandler { handleError(error) { // an error occurred in a service class method. console.log('Error in MyErrorhandler - %s', error); if(error == 'Something went wrong'){ ...

When a user clicks on the download link, it redirects them to the homepage in Angular

When using Angular 6 and the downloadFile method to download an Excel sheet from the WebAPI, everything runs smoothly. A dialog box opens up asking to save the file on the drive, but then it unexpectedly navigates me back to the home page. This redirects ...

Create a recursive CSS style for an angular template and its container

I am struggling with styling CSS inside an ng-container that is used in a tree recursive call to display a tree hierarchy. <ul> <ng-template #recursiveList let-list> <li *ngFor="let item of list" [selected]="isSelected"> <sp ...

When running npm test in Angular 12, an error message pops up saying "Failed to load color version"

After transitioning our application from angular 6 to 12, everything seemed fine as I was able to successfully run the application using 'npm start' and test its UI features. However, upon attempting to run my angular unit tests with 'npm ru ...

How to easily deactivate an input field within a MatFormField in Angular

I've come across similar questions on this topic, but none of the solutions seem to work for me as they rely on either AngularJS or JQuery. Within Angular 5, my goal is to disable the <input> within a <mat-form-field>: test.component.h ...

The ActivatedRoute.routeConfig object appears to be empty in an Angular 2 project built with Angular-cli

Two projects I've created using angular-cli are working perfectly fine. However, in one of them, the routeConfig is showing as null and I can't figure out what's causing this issue. Both projects have identical package.json files, so there ...

Issue with Lazy Loading in Angular 4 Universal

I recently created a new Angular CLI project to delve into server-side rendering with Angular Universal. Everything was set up and running smoothly, until I decided to implement lazy-loading for a module named 'lazy'. After implementing lazy-lo ...

After changing routes in Angular 4, the application experiences decreased speed and a continual increase in the number of nodes, particularly noticeable in Chrome but not in Firefox

After switching routes multiple times, I noticed a decrease in the app's speed. Upon inspecting the 'performance + memory' section using Chrome debugger, I observed an increasing number of DOM nodes. It seems that the DOM nodes are not prop ...

When attempting to showcase an image within an Angular form, the error message "Form control with unspecified name attribute lacks a value accessor" is displayed

I have a scenario where I am overlaying icons on an image within my ngForm. The goal is to allow users to drag the icons and save their new location when the form is submitted. Everything works as expected, but I encounter a pesky error whenever the page l ...

Deactivate dates in angular material date range picker after a certain number of days

Utilizing the latest version 16 of Angular material date range picker with active action buttons as shown in this image https://i.stack.imgur.com/srZGn.png My current goal is to disable a specific number of days following the selected start date. For inst ...

The View does not get updated by Angular's *ngFor directive

When I modify the Array of servers from outside the class declaration, the View/HTML component does not update accordingly. However, when I perform the same modification from inside the class, it works fine. Both functions successfully update the servers A ...

Utilize NestJS to retrieve information from an observable gRPC service

One of the challenges I am facing is using gRPC service to facilitate communication between my microservices. Specifically, when receiving a response from the Grpc service, I need to apply some modifications and additional functionality before returning a ...

Where does the browser retrieve the source files for "sourcemapped" JavaScript files from?

As I begin working on an existing project built with angular JS, upon opening chrome dev tools and navigating to the "source" view, a message appears: Source map detected... This prompts me to see a link to: https://i.stack.imgur.com/RZKcq.png The fi ...

Unable to establish a connection with ngModel despite the FormsModule module being successfully imported

I'm currently following the tutorial Tour of Heroes and I've reached a point where I need to add my first input field. Even though I have included FormsModule in AppModule, I keep getting an error saying "ng Can't bind to '{ngModel}&apo ...

Is there a way in Angular Material to consistently display both the step values and a personalized description for each step?

Is there a way to display both numerical step values and corresponding custom text in Angular Material? I prefer having the number at the top and the descriptive text at the bottom. Check out this image for reference: https://i.stack.imgur.com/LGMIO.png ...

The Angular2 Router directs the user to the main Component

After configuring the Angular2 router and setting up the server (asp.net core) to redirect unknown paths to /index.html, the routing appears to be functioning properly. However, I am encountering an issue where visiting a specific URL (i.e. www.sitename.co ...