ngModel shows the same values for distinct fields

Currently working on an Angular 5 and Firestore project, where I have implemented a form using [(ngModel)] to update a document in the database. The update operation is successful, however, there seems to be an issue with how the [(ngModel)] is displaying the document field values in the input boxes. Instead of showing different values in each input box, they all display the same value. For example:

Within the database, the document appears as follows:

document
  field1: document title
  field2: google
  field3: https://www.google.com

But when displayed in the input boxes, it looks like this:

input box 1 displays https://www.google.com

input box 2 displays https://www.google.com

input box 3 displays https://www.google.com

Here is the HTML structure being used:

<ng-container *ngFor="let x of xyz | async">
  <div class="columns">
    <div class="column">
      <form>
        <input [(ngModel)]="x.field1" #v1>
        <input [(ngModel)]="x.field2" #v2>
        <input [(ngModel)]="x.field3" #v3>
        <button (click)="update(v1.value, v2.value, v3.value)">update</button>
      </form>
    </div>
    <div class="column">
      {{x.field1}} #### <-- THESE WORK FINE
      {{x.field2}}
      {{x.field3}}
    </div>
  </div>
</ng-container>

Is there something missing in the component.ts file that I should be aware of?

Answer №1

It is essential to assign distinctive names to each of your input fields.

Answer №2

It is advisable to eliminate the form tag as using ngmodel within it may lead to issues.

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

TypeScript: empty JSON response

I am encountering an issue with the JSON data being blank in the code below. The class is defined as follows: export class Account { public amount: string; public name: string; constructor(amount: string, name: string) { this.amount = amount; t ...

Error in TypeScript due to object being undefined

Exploring TypeScript and facing a challenge with setting properties in an Angular component. When I attempt to define properties on an object, I encounter an error message: ERROR TypeError: Cannot set property 'ooyalaId' of undefined Here is ho ...

Sharing an application variable across all components in Angular - Tips and Tricks

I am currently working on a project using Angular7 for the frontend and Flask for the backend. My goal is to subscribe to a service, retrieve the data it returns, save it as an object type variable within my main AppComponent, and then access this variable ...

What are the best methods for implementing runtime type checking in JavaScript?

Utilizing either TypeScript or Facebook's Flow (type), I am empowered to statically assign types to variables like this: function add (x: integer, y: integer) { ... } Both TypeScript and Flow are able to identify and prevent incorrect invocations su ...

Ways to ascertain whether a user has successfully logged in

Just diving into Angular testing and decided to test out the checkLogin function within my application. import { Component, OnInit } from '@angular/core'; import { Router } from '@angular/router'; import {AuthenticationService} from &qu ...

What could be the reason for the Angular2 Component property not appearing on my webpage?

Here is the code snippet I am working with: import {Component} from "@angular/core"; @Component({ selector: 'my-app', template: ` <h1>{{title}}</h1> <h2>{{secondTitle}}</h2> <main-page></ma ...

Strategies for resolving the "Objects are invalid React children" issue in Next.js 13 and Next Auth

I am currently developing an application using Next JS 13 with Firebase and Next Auth. After integrating Firebase with Next Auth and utilizing the session, I encountered an error. Error: Objects are not valid as a React child (found: [object Promise]). If ...

Having trouble compiling an Ionic/Cordova app for Android?

I have encountered an issue while trying to build my Ionic/Cordova app for Android. It runs smoothly on iOS, but when attempting to build for Android, I keep receiving an error message. The specific error is: Error: Attribute meta-data#android.support.V ...

The error message "Property does not exist on type Object from subscribe" indicates that

When using forkJoin to make multiple http calls, I encountered the error error TS2339: Property 'data' does not exist on type 'Object' forkJoin(this.userservice.getUser(), this.userservice.getDashboard()).pipe( map(([userData, dash ...

Communicate between sibling components in Angular by passing the selector of one component to another

Within my project, I have two sibling components located in the SecondComponent folder. The SecondComponent consists of both the main component and its child component. Now, in the FirstComponent, I need to access the child component of the SecondComponent ...

The ordering of my styles and Material-UI styles is causing conflicts and overrides

Greetings fellow developers! I'm currently facing an issue with my custom styles created using makeStyles(...). The problem arises when I import my styles constant from another module, and the order of the style block is causing my styles to be overr ...

Elements can only be added to the array at the 0th index

In the process of developing a function, I encountered an issue where all elements added to the array were only stored in Array[0] of the rowData. The data is retrieved from a database. private createRowData() { var rowData:any[] = []; thi ...

What is the method to invoke a function within another function in Angular 9?

Illustration ` function1(){ ------- main function execution function2(){ ------child function execution } } ` I must invoke function2 in TypeScript ...

Enhancing the getDate function in JavaScript with additional days

My function for selecting the date is working perfectly: formatDateField(event: Date, formControl: string) { this.form .get(formControl) .patchValue( this.datePipe.transform(event.getTime(), "yyyy-MM-dd'T'HH:mm:ss&quo ...

Having trouble with updating operations in MEAN stack CRUD functionalities

While implementing CRUD operations, I encountered an issue with the update function. Even though I followed a tutorial (https://www.youtube.com/watch?v=fhRdqbEXp9Y) and customized the code to suit my application, the update operation is not working as expe ...

Strategies for handling superfluous or calculated information within Angular form components

I am faced with a challenge in managing informative fields within my component, especially when some inputs are derived from others. For instance, consider an order that includes a product ID and an amount. Here is a scenario: If a product is selected, I ...

Having trouble integrating a Bootstrap-based ecommerce theme into an Angular8 project?

I have a bootstrap-based ecommerce theme with all the necessary files. The HTML theme is loading perfectly. Check out the official theme page I am integrating into my angular8 project: Theme Page Link I have created a repository for my angular8 project ...

Error in Typescript: Attempting to access the property 'set' of an undefined value

Currently, I am in the process of setting up a basic example of push notifications on Android using Nativescript and Typescript. Although my code may seem a bit messy, I am struggling with properly rewriting "var Observable = require("data/observable");" a ...

Troubleshooting: Vue.js component events not being detected in TypeScript

I'm encountering an issue with receiving events from a barcode reader, which I heavily referenced from a GitHub repository. The problem lies in the fact that the events emitted by the BarcodeScanner component are not being captured by the enclosing c ...

Guide on optimizing Angular CLI production builds with gzip compression

When I build my angular project using ng build --environment=${environment}, the bundle files created are quite large. The version of "@angular/compiler-cli": "^4.0.0" does not generate .gz files in the dist folder. Is there a simple way to create .gz bu ...