0

let for an instance

    {
    "E-mail Address": "[email protected]",
    "Related name": "",
    "Home Address 2": "",
    "Anniversary": "",
    "First Name": "Rios",
    "Business Address 2": "",
    "Department": "",
    "Display Name": "Baker Adkins",
    "Home State": "",
    "Business Country": "",
    "Home Street": "",
    "Birthday": "",
    "Home Country": "",
    "Pager": "",
    "Categories": "",
    "Home City": "",
    "E-mail 3 Address": "[email protected]",
    "Home Fax": "",
    "Gender": "",
    "Notes": "proident",
    "Country Code": "",
    "Job Title": "",
    "Business Address": "",
    "Web Page 2": "",
    "Mobile Phone": "",
    "Organization": "",
    "Home Phone": "(962) 514-3534",
    "E-mail 2 Address": "[email protected]",
    "Last Name": "Fisher",
    "Nickname": "",
    "Business Fax": "",
    "Home Postal Code": "",
    "Business Phone": "",
    "Business Postal Code": "",
    "Web Page": "",
    "Business City": "",
    "Business State": ""
  }
   <input ng-model="disName" type="text">

this is a specific object in a array of objects. How can I modify a specific value for a key for suppose [key = Display Name] and with change in input value how can I modify it in object?

1 Answer 1

1

In angularJS you'll bind the object property to the input using ng-model. There's no need to listen any change, because the framework takes care of that.

¿Who provides this object to the <input>? The controller, exposing the object through this.

Here's a working example using components.

https://plnkr.co/edit/lfD1LgML0nuRURKX4DCw?p=preview

As you can see, you'll need to use bracket notation because of the use of spaces on your object keys...

<input ng-model="$ctrl.obj['Display Name']">

On a real world example, I suppose your data will be provided using a service, as you can see in this example:

https://plnkr.co/edit/fp1fBC59dJLettJBvD2p?p=preview

Hope it helps!

Sign up to request clarification or add additional context in comments.

2 Comments

/*HTML: */ <input ng-model="firstName" type="text" class="editable"> /*Angular: */ var contactToEdit = outText.find(x => x["Display Name"] === $scope.disName); contactToEdit["First Name"] = $scope.firstName; What if I do this way. Isn't it an effective approach
but when do you tell angular to do the assignment? if you're thinking on ng-change, that's we wanted to avoid, and that's what ng-model is for...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.