retrieving data from ngModel and saving it in a variable

Currently, I am working on inline editing in my application. I am retrieving data from an API and storing the value inside an input using ngModel. I have a custom object named editCat and editCarSub that I need to send to the API. How can I extract the value from the input and store it inside my object?

If you want to see the code in action, check out this StackBlitz.

.ts

  done(id, index) {
    this.editCat = {
      carPartCategoryId: id,
      name: '', //input value here
    };
    this.hidemeSub[index] = false;
    console.log(this.editCat);
  }

.html

<div *ngFor="let item of items; let index = index">
  <div class="d-flex align-items-center">
    <span [hidden]="hidemeSub[index]">{{ item.name }}</span>
    <div
      class="btn"
      (click)="hidemeSub[index] = !hidemeSub[index]"
      [hidden]="hidemeSub[index]">
      Edit
    </div>
  </div>
  <div class="d-flex pl-3">
    <input type="text" [hidden]="!hidemeSub[index]" [(ngModel)]="item.name" />
    <div
      class="btn"
      [hidden]="!hidemeSub[index]"
      (click)="done(item.carPartCategoryId, index)">
      Done
    </div>
  </div>
</div>

Answer №1

Include the item name in the done function

(click)="done(item.carPartCategoryId, item.name, index)"

Followed by

done(id, name, index) {
  this.editCat = {
    carPartCategoryId: id,
    name: name, //insert input value here
  };
  this.hidemeSub[index] = false;
  console.log(this.editCat);
}

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

Contrasting `Function` with `(...args: any[]) => any`

Can you explain the difference between Function and (...args: any[]) => any? I recently discovered that Function cannot be assigned to (...args: any[]) => any. Why is that so puzzling? declare let foo: Function; declare let bar: (...args: an ...

Tips for automatically expanding the pivot column groups in angular ag-grid by default

Currently, I am utilizing angular ag-grid for data display purposes. My goal is to have the pivot column group automatically expanded and to remove the expand and collapse icon for the pivot column. I have developed a demonstration which can be found at ...

Error: Attempting to access 'update' property of a null value

function logUserOut(user: UserInstance) { return user.update({ token: null }); } I encountered an error at this part of the code. Any suggestions on how to fix it? ...

What should I use - npm types, typings, @type, or something else?

I am currently working with VS 2015 update 3, Angular 2.1.2, and Typescript 2.0.6. Could someone provide clarity on the differences between typings, npm @types, and any other elusive documentation that may be relevant this month? Or perhaps direct me to ...

Concealing input special characters with Angular 8

Is there a way to display credit card numbers in an input field with a bullet special character look? 4444 •••• •••• 4444 I'm attempting to achieve this using a pipe in Angular without relying on any input mask plugins. Here's w ...

Utilize the parameters from the config.json file within the application

We've integrated the Google Maps API into our project and have generated a key for it. Currently, this key is hardcoded in one of our module files. However, we want to enhance security by moving this key into the config.json file. This way, when we pu ...

Error message: Angular 2's NgFor directive can only bind to iterable data types like Arrays

One of the challenges I'm facing involves working with a specific model: export class CoreGoalModel { constructor( public title: string, public image: string, ){} } In order to retrieve data based on this model, I've set up a s ...

Unleashing the power of ::ng-deep to access CSS in an Angular child component

I'm attempting to modify the CSS class of a child component by using ::ng-deep. Despite my efforts with various iterations of the code provided below, I have been unsuccessful in accessing the CSS. The structure of the HTML component is depicted in th ...

Event for Angular 4 mat-datepicker triggering on date selection change

I currently have a date picker feature implemented in my application. Here is the code snippet: <mat-form-field> <input mdInput [matDatepicker]="dp3" placeholder="Select Birthday" name="birthday" disabled> <mat-datepicker-toggle ...

Managing variables or properties that are not defined in ES6

Currently, I am utilizing Angular and Firebase Firestore in my project. However, the question posed could be relevant to Typescript and pure Javascript as well. The functionality of my application relies heavily on the data retrieved from Firestore. A sim ...

Seasonal calendar selector

Currently, I am searching for a Quarterly date picker utilizing ng-bootstrap. Right now, I already have a Month and Year picker, as shown in this STACKBLITZ, but my goal is to switch the Month to Quarter. https://i.sstatic.net/1kWN3.png Can ng-bootstrap ...

Developing an exportable value service type in TypeScript for AngularJS

I have been working on creating a valuable service using typescript that involves a basic switch case statement based on values from the collection provided below [{ book_id: 1, year_published: 2000 }, { book_id: 2, year_publish ...

Angular router.redirect is not able to pass variables as expected

I am facing an issue with the router redirect and template lifecycle while using Stripe checkout in my Angular 5 project. After a user signs up, I trigger the stripe checkout modal. Once the modal receives a payment source token, I perform some additional ...

Angular CLI version 7 experiencing issues with POST requests

When I attempted to send an http request, I followed the guidelines provided in this documentation and created the following service. Although I used Angular version 5 syntax, the function did not execute as expected. createCartProduct(cartpr : CartProdu ...

Tips for leveraging generics in Angular CDK's Dialog.open<?????>

Currently, I am in the process of determining which interfaces to include within the generics section of the open function found in Angular's CDK Dialog. It is important to note that this is not related to Angular Material. Here is what I have been a ...

Guide to dynamically including a tooltip in an input box using Angular 2

I need to implement a feature where a Tooltip message is displayed when hovering over an input box. The content of the Tooltip message will depend on the response received from a service. If the service responds with 'true', the Tooltip message s ...

Maximizing the potential of mouse positioning in Angular

I am working with an Angular form that has a textarea <textarea class="form-control" id="message" formControlName="message" (fo ...

Working with the Android back button in Ionic 2

I have been working on managing the android back button in ionic 2. Below is the code I have implemented to allow users to exit the app when they are on the home page or login page: let alert = this.alertCtrl.create({ title: 'Kmart', ...

What is the method for passing an element in Angular2 Typescript binding?

Is there a way to retrieve the specific HTML dom element passed through a binding in Angular? I'm having trouble figuring it out, so here is the relevant code snippet: donut-chart.html <div class="donut-chart" (donut)="$element"> ...

Exploring the capabilities of Angular2 in conjunction with Symfony3's FOSOAuthServerBundle for secure

Trying to integrate my angular2 frontend app with a symfony backend. Currently using FOSOAuthServerBundle (https://github.com/FriendsOfSymfony/FOSOAuthServerBundle) for authorization, but struggling to fully grasp the implementation process. Experiment ...