`Angular Model Value Bin for Arrays causing a bug`

I am attempting to link API values to HTML using *ngFor, and here is the code I have:

HTML

<nb-card accent="info">
  <nb-card-header>Item Quantity</nb-card-header>
  <nb-card-body>
    <div *ngFor="let location of StoreLocations;let i=index">
      <div class="row text-box-margin" >
          <div class="col-md-5">
              <p class="label-margin">Quantity for {{location.label}}</p>
          </div>
          <div class="col-md-7">
            <input type="text" nbInput fullWidth status="primary" [(ngModel)]="location.quantity"  placeholder="Quantity">
          </div>
        </div>
    </div>

  </nb-card-body>
</nb-card>

StoreLocations = new Array() array is defined as this. Here is the definition of ILocationInfo:

export class ILocationInfo
{
  value = new String;
  label = new String;
  street = new String;
  unit = new String;
  city = new String;
  zip = new String;
  state = new String;
  country = new String;
  quantity = new Number;
  selected = new Boolean;

}

The array will be filled using an Angular resolver, so when the form loads, the values are there.

Constructor Code

  constructor(private apiservice : ApiServiceService,private route: ActivatedRoute, private formbuilder:FormBuilder) {

    this.route.data.pipe(map((data:any)=>data.cres)).subscribe((locations : Array<ILocationInfo>)=>{
      console.log(locations);
      this.StoreLocations = locations;

    });
   }

Error Message Received

core.mjs:6495 ERROR Error: NG0201: No provider for NgControl found in NodeInjector. Find more at https://angular.io/errors/NG0201
    at throwProviderNotFoundError (core.mjs:245)
    at notFoundValueOrThrow (core.mjs:3324)
    at lookupTokenUsingModuleInjector (core.mjs:3359)
    at getOrCreateInjectable (core.mjs:3461)
    at Module.ɵɵdirectiveInject (core.mjs:14720)
    at NodeInjectorFactory.NgControlStatus_Factory [as factory] (forms.mjs:1343)
    at getNodeInjectable (core.mjs:3556)
    at instantiateAllDirectives (core.mjs:10317)
    at createDirectivesInstances (core.mjs:9666)
    at ɵɵelementStart (core.mjs:14864)

Why am I getting this error even though the values are present..?

As soon as I remove

[(ngModel)]="location.quantity"
, I do not receive any errors. Can someone advise me on how to resolve this?

Imports in TypeScript file

import { Component, OnInit } from '@angular/core';
import { FormArray, FormBuilder, FormControl, FormGroup ,FormsModule} from '@angular/forms';
import { ActivatedRoute } from '@angular/router';
import { map } from 'rxjs/operators';
import { ApiServiceService } from 'src/app/API/api-service.service';
import { ILocationInfo } from 'src/app/Models/Inventory/models';

Answer №1

Seems like the forms modules have not been imported yet.

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

@NgModule({
  imports: [..., FormsModule, ...],
  ...
})
export class AppModule {...}

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

Testing in Angular using the getByRole query functionality is successful only when the hidden: true option is utilized

Currently experimenting with a new library, I'm facing difficulties accessing elements based on their ARIA role. My setup includes angular 10.0.6, jest 26.2.1, along with jest-preset-angular 8.2.1 and @testing-library/angular 10.0.1. Following instru ...

Angular automatically protects routes by default

In the application I've created, there is a requirement for most routes to be protected and accessible only when logged in. Is it feasible to implement a default route guard while also specifying certain routes that should remain open? ...

Combining an Angular application within a Spring application and encountering a TypeError on a JSP page

I am currently working on integrating an Angular app into an existing Spring application. I have included the code for integration below. While it functions correctly on some JSP pages, it fails on others. Please see the description and rendered element in ...

Angular CLI Issue: Project Configuration Not Detected

I've been attempting to execute an Angular program that was developed by a coworker, but I keep encountering the same error message: "The serve command needs to be run in an Angular project, yet a project definition cannot be found." Even after runnin ...

Angular data binding between an input element and a span element

What is the best way to connect input texts with the innerHTML of a span in Angular6? Typescript file ... finance_fullname: string; ... Template file <input type="text" id="finance_fullname" [(ngModel)]="finance_fullname"> <span class="fullnam ...

What is the method for utilizing Tuple elements as keys in a Mapped Type or template literal within typescript?

Is there a specific way to correctly type the following function in TypeScript? Assuming we have a function createMap() that requires: a prefix (e.g. foo) and a tuple of suffixes (e.g. ['a', 'b', 'c']) If we call createMap(& ...

Developing an Angular directive that accepts a function parameter using TypeScript

I've been attempting to integrate an Angular function parameter into a TypeScript directive, but it seems like my syntax is off. Here's an example of the directive code I'm working with: export class CustomDirective implements ng.IDirective ...

Issue encountered while deploying Node.js server on Render platform

I'm currently facing an issue while attempting to deploy a TypeScript server with Node.js to Render. I've provided the directory structure and deployment information below. Any insights or opinions you can offer would be greatly appreciated. Than ...

Is there a way to manage specific HTML elements in Angular?

I am working on displaying a list of enable/disable buttons for different users. The goal is to show the appropriate button for each user based on their status - enabling if disabled and disabling if enabled. To achieve this, I have utilized the flags "use ...

Pause the execution at specific points within Typescript files by utilizing breakpoints when debugging with an attached debugger in VsCode

My current challenge involves setting up a debugger in VsCode with the attach mode on a Typescript codebase running in a Docker container. Despite successfully attaching the debugger in VsCode and hitting breakpoints, I consistently find myself landing on ...

Tips for accessing query parameters within an APP_INITIALIZER service in Angular 4

I have created a unique custom ConfigService designed to retrieve configuration details before the Angular application initializes. The code snippet below is implemented within app.module.ts and successfully loads the configurations prior to the app start ...

Creating TypeScript declarations for standard JavaScript functions and objects so they can be accessed in a TypeScript project

In my TS project, I am currently using Node, Express, and Handlebars along with some client-side JS successfully. I don't have any other client-side frameworks like React or Angular integrated at this time. Recently, I have been thinking about conver ...

How can a single variable be assigned one of two potential @Inputs in Angular2+?

Currently, I am facing a challenge in defining inputs for an Angular8 Directive while also supporting a legacy Directive. My plan going forward is to name my inputs in camel-case, but the existing inputs are in kebab-case. Therefore, in order to support th ...

Using TypeScript to automatically deduce the output type of a function by analyzing the recursive input type

I am currently working on developing an ORM for a graph database using TypeScript. Specifically, I am focusing on enhancing the "find" method to retrieve a list of a specific entity. The goal is to allow the function to accept a structure detailing the joi ...

Oops! An issue occurred while trying to compile the file constructor.d.ts in the common-behaviors folder of @angular/material/core. The error message received was: "error TS1005: ';'

Switching from Bootstrap to Angular Material caused an unexpected error when trying to run ng serve: Error: node_modules/@angular/material/core/common-behaviors/constructor.d.ts:14:64 - error TS1005: ';' expected. The errors encountered include: ...

Angular 8 Refresh Token Implementation

I am currently working on an Angular 8 app that is integrated with .NET Core. My goal is to find a way to refresh a JWT token within the application. Within the integration, users are able to validate and receive a token which expires after 30 minutes. T ...

Positioning Data Labels Outside of Pie or Doughnut Charts in Chart.js

I am currently working on a large-scale project and I am in need of a way to position the labels outside of pie charts or doughnut charts. I came across a plugin called outerLabels on GitHub which seems to be the perfect solution for what I need, but I am ...

The componentWillReceiveProps method is not triggered when a property is removed from an object prop

Just starting out with React, so I could really use some assistance from the community! I am working with a prop called 'sampleProp' which is defined as follows: sampleProp = {key:0, value:[]} When I click a button, I am trying to remo ...

Unlocking the Magic: A Step-by-Step Guide to Generating PDFs with

I'm currently engaged in developing an IONIC venture employing JavaScript and Angular. One of the tasks entails creating a comprehensive PDF report featuring text, images, and graphs. Instead of hand-crafting all the elements, I'm keen on adoptin ...

Having trouble setting a default value within an Angular component using ControlValueAccessor?

Demo: https://plnkr.co/edit/cMu3lI3PkxHRErJE3T93?p=preview I've encountered an issue with setting default values for ngModel or formControlName when using ControlValueAccessor in multiple components. For instance, in the provided demo, there is a se ...