Why is the input box not opening when I click on the edit icon?

Whenever the edit button is clicked, the input box does not open. After clicking on the edit option and then clicking on another input box, it will be changed to an input box. I want the input box to change when the edit option is clicked.

                    <form class="form-add-expenses" (submit)="addItem($event)">
                    <div class="row">
                        <div class="col-sm-2">
                            <input type="text" class="form-control" [(ngModel)]="masterItem.itemName" placeholder="Item Name" name="name">
                        </div>
                        <div class="col-sm-2">
                            <input type="text" class="form-control" [(ngModel)]="masterItem.itemType" placeholder="Item Type" name="type">
                        </div>
                        <div class="col-sm-5">
                            <input type="text" class="form-control" [(ngModel)]="masterItem.itemDescription" placeholder="Item Description" name="description">
                        </div>
                        <div class="col-sm-2">
                            <input type="text" class="form-control" [(ngModel)]="masterItem.itemCurrentPrice" placeholder="Item Price" name="price">
                        </div>
                        <div class="col-sm-1">
                            <button type="submit" class="btn btn-md">add</button>
                        </div>
                    </div>
                </form>
                <table class="table-responsive table-bordered table-striped">
                  <thead>
                    <tr>
                        <th>Name</th>
                        <th>Type</th>
                        <th>Description</th>
                        <th>Price</th>
                        <th>Edit</th>
                        <th>Delete</th>
                    </tr>
                  </thead>
                  <tbody>
                        <tr *ngFor="let item of items; let i=index">
                        <td><!-- {{ item.itemName }} -->
                            <span *ngIf="i !== indexes">{{ item.itemName }}</span>
                            <span *ngIf="i === indexes"><input type="text" class="form-control" [(ngModel)]="editUpdate.itemName" name="update.name" (keyup.enter)="UpdateItem()" (keyup.escape)="cancelEditingTodo()"></span>
                        </td>
                        <td><!-- {{ item.itemType }} -->
                            <span *ngIf="i !== indexes">{{ item.itemType }}</span>
                            <span *ngIf="i === indexes"><input type="text" class="form-control" [(ngModel)]="editUpdate.itemType" name="update.type" (keyup.enter)="UpdateItem()" (keyup.escape)="cancelEditingTodo()"></span>
                        </td>
                        <td><!-- {{ item.itemDescription }} -->
                            <span *ngIf="i !== indexes">{{ item.itemDescription }}</span>
                            <span *ngIf="i === indexes"><input type="text" class="form-control" [(ngModel)]="editUpdate.itemDescription" name="update.description" (keyup.enter)="UpdateItem()" (keyup.escape)="cancelEditingTodo()"></span>
                        </td>
                        <td><!-- {{ item.itemCurrentPrice }} -->
                            <span *ngIf="i !== indexes">{{ item.itemCurrentPrice }}</span>
                            <span *ngIf="i === indexes"><input type="text" class="form-control" [(ngModel)]="editUpdate.itemCurrentPrice" name="update.price" (keyup.enter)="UpdateItem()" (keyup.escape)="cancelEditingTodo()"></span>
                        </td>
                        <td>
                            <span *ngIf="i !== indexes"><i class="fa fa-pencil" (click)="editItem(i)" aria-hidden="true"></i></span>
                            <span *ngIf="i === indexes"><button (click)="UpdateItem()" class="btn btn-md">Update</button></span>
                        </td>
                        <td><i class="fa fa-trash" (click)="deleteItem(i)" aria-hidden="true"></i></td>
                    </tr>
                  </tbody>
                </table>

My TypeScript file is:

editItem(i: number) {
    this.indexes = i;
    this.editUpdate = this.items[this.indexes];
    console.log("edit",this.editUpdate);
}

Answer №1

Utilize the

ChangeDetectorRef.detectChanges()

method in order to apply any changes. This function acts similar to $scope.$digest() and manually triggers the update process, ensuring that the changes are reflected in your view. Sometimes, the digest cycle may not automatically trigger to update these changes.

This should provide assistance.

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

Svelte language switcher experiencing technical difficulties

Currently delving into Svelte 3, I embarked on a project intended to be shared on GitHub in English. However, I realized that some of my friends do not speak English. To accommodate different language preferences, I decided to create a language switcher. H ...

Optimize a feature by implementing it as a modal in Angular version 5

I am currently working on an Angular 5 project that features a side panel with a master/detail view. My goal is to allow users to maximize the detail component in a modal dialog by clicking a button within this component - similar to the behavior found in ...

Honing into Angular 2 Events

I am struggling with something that should be simple, but I can't seem to make it work. My goal is to utilize screenfull, which is included in a theme I'm using, to enable fullscreen mode on the browser. Specifically, I want to execute certain ac ...

Angular App Failing to Validate Session Cookie 'sessionId' in AuthGuard

Encountering a perplexing issue with my Angular application where the AuthGuard fails to recognize a session cookie named 'sessionId' correctly. I have successfully implemented user authentication, and the expected behavior is for users to be dir ...

Troubleshooting issue with Ionic FilePath: How to retrieve file path in Android 11

Recently, I've been looking into the changes in the Android file system due to the release of Android 11. Currently, I am encountering an issue with opening a file using the Android File Chooser from within my Ionic app. https://ionicframework.com/do ...

Utilize a variable within an HTML attribute

Currently utilizing Angular and I have the following HTML snippet <input onKeyDown="if(this.value.length==12 && event.keyCode!=8) return false;"/> Is there a way for me to incorporate the variable "myNum" instead of the ...

Transforming the string attribute of an object within a JavaScript array through mapping

Here is an array of objects: { "attr1": 123, "attr2": "a.end", }, { "attr1": 123, "attr2": "b.start", } The task is to remove the first part of the attr2 string up to and including the '.& ...

Difficulty accessing files with Angular deployment in Nginx through Docker

Recently, I delved into the world of Docker and Nginx in an attempt to deploy my angular application. Unfortunately, I encountered a perplexing issue. Upon executing the command: npm run build, I noticed that my index.html contained script references as f ...

Issue with bidirectional data binding in Angular 2 on input element not functioning as expected

Looking at the code snippet below, I have noticed that even though the textchange function is called when the input value changes, the text property of the InputMaskComponent remains constant. I am not able to identify the issue in my code. InputMaskCompo ...

Strategies for capturing unhashed routes through the use of a hashed location strategy

I can't seem to figure this out. Our application is using HashLocationStrategy, which we need to keep in some cases. However, I need to detect specific paths that contain a series of numbers like this: www.someurl.com/1241234 I've created an Ang ...

Transforming the Oracle JSON response into a variable in Angular 2

After successfully setting up a service using Express API and Node to retrieve data from an Oracle DB, I am facing an issue with mapping the JSON response to an Angular variable. Even though I have created an Angular service and component, I can't see ...

What is the best method to make changes to a user in Firebase using AngularFire2?

Creating a user is simple with this code snippet: this.af.auth.createUser({email: email, password: password}); However, once the user is created, how can their details be edited? For example, changing the password or email address. I attempted the follow ...

Steer clear of encapsulating components or modifying the attributes of the encapsulating element

I am currently developing an application that involves dynamically adding components. One of the key components is a block component with the following template: <div id="{{element.id}}" class="row" [hidden]="hide"> ...

Navigating with Angular: Transmitting dynamic URL parameters to components

I currently have the following routes defined: const routes: Routes = [ { path: ':product/new', children: [{ path: 'std/:country', component: SignUpComponent, data: { ...

Tips for troubleshooting an error in ionic when compiling a template

Hello, I'm currently working on my first app but encountered an error during the extraction process. ? Starter template: my-first-app √ Preparing directory .\testarashelia - done! > git.exe clone https://github.com/ionic-team/photo-gallery- ...

Can you provide some instances of attribute directives?

I'm struggling to understand when it's best to implement an attribute directive, know when an attribute directive is necessary, utilize input and output properties Why should I use an attribute directive? I often find myself combining all l ...

How can I verify the validity of a regular expression in Typescript without encountering a syntax error?

I am facing an issue with my code where I load a set of regular expressions from an external source. My goal is to determine if a given string is a valid regex without causing the application to crash due to a syntax error. Despite trying to use try/catch ...

Angular2 Routing error. Index 1 in the requested path is undefined

Having trouble with routing in Angular 2. I am calling router.navigate from an action within a data table. The strange thing is that sometimes when I click the button to trigger this line, it works perfectly fine, but other times it doesn't. this.rou ...

Combining pixijs with TypeScript in Ionic 2 using npm

To begin, I ran the command npm install -g ionic Followed by ionic start pixiApp blank --v2 Navigated to the pixiApp directory with cd pixiApp Installed necessary dependencies using npm install Added a specific version of pixi.js (4.1.0) with npm install p ...

Having issues with using the class selector in SVG.select() method of the svg.js library when working with TypeScript

Exploring the capabilities of the svg.js library with typescript has presented some challenges when it comes to utilizing CSS selectors. My goal is to select an SVG element using the select() method with a class selector. In this interactive example, this ...