Error: ngModel does not reflect dynamic changes in value

After calling a Spring service, I am receiving JSON data which is stored in the "etapaData" variable.

0:
id: 266
aplicacao: {id: 192, nome: "Sistema de Cadastro", checked: false}
erro: {id: 220, nome: "Falta de orçamento", checked: false}
perfil: {id: 8, nome: "Usuario", checked: false}
checked: true
ordem: 1
tarefas: [{…}]
__proto__: Object
1:
id: 267
aplicacao: {id: 204, nome: "Sistema Financeiro", checked: false}
erro: {id: 237, nome: "Número de licenças excedidas", checked: false}
perfil: {id: 188, nome: "Administrador", checked: false}
checked: true
ordem: 2
tarefas: [{…}]
__proto__: Object
2:
id: 269
aplicacao: {id: 204, nome: "Sistema Financeiro", checked: false}
erro: {id: 221, nome: "Nullpointer Exception", checked: false}
perfil: {id: 10, nome: "N2", checked: false}
checked: true
ordem: 3
tarefas: (2) [{…}, {…}]
__proto__: Object
length: 3

When rendering this JSON in HTML, the "ordem" value is not loading correctly. All three elements are being displayed with the value "3", instead of "1", "2" and "3":

https://i.sstatic.net/fWYBS.png

The expected values should be "1," "2," and "3."

This snippet shows the relevant HTML code:

<div class="container" style="padding-left: 60px;">
    <div class="panel panel-default">
        <div class="panel-heading">
            <h1>Atualizar Workflow</h1>

        <div [hidden]="submitted">
            <form (ngSubmit)="onSubmit()">
                <h4>Nome</h4>  
                <div class="input-field col s6">                    
                    <input placeholder="Digite o nome do Workflow" type="text" class="form-control" id="nome" required [(ngModel)]="workflow.nome"
                        name="nome">
                </div>
                <h4>Etapas</h4>                
                <table class="table table-striped table-bordered">
                    <thead>
                        <tr>
                            <th>Check</th>
                            <th>Aplicação</th>
                            <th>Erro</th>
                            <th>Time</th>
                            <th>Tarefas</th>
                            <th>Ordem</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr *ngFor="let etapa of etapaData">
                            <td><input type='checkbox' id="etapa{{etapa.id}}" [checked]="etapa.checked" class="valign-wrapper"><label
                                    class="valign-wrapper" for="etapa{{etapa.id}}"></label></td>
                            <td>{{etapa.aplicacao.nome}}</td>
                            <td>{{etapa.erro.nome}}</td>
                            <td>{{etapa.perfil.nome}}</td>
                            <div *ngFor="let tarefa of etapa.tarefas">{{tarefa.nome}}</div>
                            <td><label for="ordem"></label>
                                <input placeholder="Ordem da etapa no Workflow" type="text" class="form-control" id="ordem{{etapa.id}}" required
                                    [(ngModel)]="etapa.ordem" name="etapa.ordem"></td>
                        </tr>
                    </tbody>
                </table>
                <div class="input-field">
                    <button type="submit" class="btn btn-success">Submit<i
                            class="material-icons right">send</i></button>
                </div>
            </form>
        </div>
            <div class="alert alert-success" role="alert" [hidden]="!submitted">
                <h4>Registro submetido com sucesso!</h4>
            </div>
        </div>
    </div>
</div>

Is there something wrong with my implementation?

Answer №1

I believe the correct code to use is:

<input placeholder="Order of the step in Workflow" type="text" class="form-control" id="ordem{{etapa.id}}" required value="{{ etapa.ordem }}" name="etapa.ordem">

Answer №2

Based on the information from the documentation

According to Angular docs, each input element must have a name property in order for Angular forms to properly register the control within the form. Check out the Angular Document for more details.

I noticed that the name property seems to be the same for all inputs in the for loop. Could you please verify this?

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

Is it possible to utilize enums as keys in a Json structure?

I am currently utilizing TypeScript in conjunction with Node.js (MEAN stack). My aim is to incorporate an enum within the property/schema of a JSON object. An example of the enum would be: enum KeyEnums { A: "featureA", B: "featureB&qu ...

TypeScript and Angular: Harnessing the Power of Directive Dependency Injection

There are multiple approaches to creating Angular directives in TypeScript. One elegant method involves using a static factory function: module app { export class myDirective implements ng.IDirective { restrict: string = "E"; replace: ...

Mono repo project utilizing Angular 4+ and Typescript, enhanced with Bootstrap styling

Looking for a project to practice with Angular 4+ using Typescript and a Bootstrap template. Hoping for a setup where I can just run npm install and ng serve to start. Any recommendations for mono repos would be highly valued! ...

Development of backend applications using Node.js and Express, coupled with frontend interfaces built with Angular

I created a web application, utilizing Node.js with Express and MySQL for the backend, and Angular framework for the frontend. Check here While everything works smoothly in my local environment (using Mamp and port 3000 for testing), I am encountering dif ...

Error encountered while testing karma: subscription function is not recognized

I encountered an issue with my karma unit test failing with the following error message. "this.gridApi.getScaleWidth().subscribe is not a function" GridApi.ts export class GridApi { private scaleWidthSubject = new BehaviorSubject<{value: number}& ...

Just completed the upgrade of my Angular project from version 9 to version 12, but now encountering issues with a module that utilizes Plotly

Here is the content of my app module file. All components and imports are in their respective places as specified in the documentation: import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from &apos ...

What is the best way to transfer information from a model to the screen?

I need assistance with adding a Todo using a model. When I click the Add todo button located at the bottom of the page, it opens the model. I want to be able to add whatever I type in the input field to the list. How can I send the input field data to the ...

Ionic 3: Struggling to Access Promise Value Outside Function

I've encountered an issue where I am unable to retrieve the value of a promise outside of my function. It keeps returning undefined. Here's what I have attempted so far: Home.ts class Home{ dd:any; constructor(public dbHelpr:DbHelperProvider ...

Observe how Observable breaks down strings into individual letters (like in Karma and Angular)

Attempting to simulate an HTTP service in Angular tests (Karma), I included the following in the providers array: { provide: service, useValue: { getData: () => new Observable((subscriber) => { subscriber.next('i ...

Leveraging an external TypeScript library in a TypeScript internal module

Imagine you find yourself in a situation where you need to utilize a typescript/node library within an internal module that is spanned across multiple .ts files. ApiRepositoryHelper.ts import * as requestPromise from "request-promise"; module ApiHelp ...

Loading a large quantity of items into state in React Context using Typescript

I am currently working on a React context where I need to bulk load items into the state rather than loading one item at a time using a reducer. The issue lies in the Provider initialization section of the code, specifically in handling the api fetch call ...

Unleash the power of a module by exposing it to the global Window object using the dynamic

In my development process, I am utilizing webpack to bundle and manage my TypeScript modules. However, I am facing a challenge where I need certain modules or chunks to be accessible externally. Can anyone guide me on how to achieve this? Additional conte ...

incapable of altering the function of individual parts within ionic 3

I am currently working on creating a list of people for users to connect with. When a user clicks on the connect button, it should send a connection request to the chosen person. However, I am facing an issue where clicking on the connect button changes th ...

Functions have been successfully deployed, but they are not appearing on the Azure Portal

I am experiencing difficulties deploying basic Typescript functions to Azure. Despite a successful deployment using VS code and confirmation in the Output window, I cannot see any functions listed in the Azure Portal under the Function App: https://i.stac ...

The proper way to cancel useEffect's Async in TypeScript

I'm facing an issue with this straightforward example: useEffect(() => { axios.get(...).then(...).catch(...) }, [props.foo]) warning: can't perform a react state update on an unmounted component After some investigation, I found this ...

Enter the newest addition of the node.js layer that bridges the gap between user interface and

Currently, I am in the process of creating a solution on AWS that relies on Cognito for managing users. To kickstart this project, I have referenced the SAAS QuickStart guide available at: SAAS QuickStart However, I am making a significant change by aim ...

Angular protection filter

Every time I used Angular CLI to generate a new component, it would create the component with standard parameters: @Component({ selector: 'app-test1', templateUrl: './test1.component.html', styleUrls: ['./test1.component.css ...

Showing user's email post login in Angular 11

Currently, I am working on a project using Angular 11 and .NET Core with web API JWT token authentication to handle user Login functionality. I have successfully implemented the user login feature, which redirects users to the dashboard upon successful aut ...

Angular 5 using AngularFire for Seamless Firebase Login Experience

Utilizing AngularFire2 in combination with Firebase and Angular 5, I have successfully implemented a login system. However, upon refreshing the page, a slight flicker occurs due to the delay in loading JavaScript. This issue is unfamiliar to me as I'm ...

I have a quick question: What is the most effective method for creating PDF templates with Angular and .NET 6, specifically for designs that feature heavy

Seeking the optimal solution for creating PDF templates using Angular and .NET 6? Specifically looking to design templates that heavily feature tables. In my exploration of efficient PDF template creation with Angular and .NET 6, I ventured into using pdf ...