Angular use array value for oject

Kiwi

So I'm trying to set some object values via the values in an array.

$scope.ngmodelfield = {};
$scope.categories = [{
  cat: "Cat 1a",
  translationTag: "OccupationalSafety"
}, {
  cat: "Cat 1b",
  translationTag: "IndustrialSafety"
}, {
  cat: "Cat 2",
  translationTag: "Growth"
}, {
  cat: "Cat 3",
  translationTag: "Modifications"
}, {
  cat: "Cat 4",
  translationTag: "Maintenance"
}, {
  cat: "Cat 5",
  translationTag: "Renewals"
}, {
  cat: "Cat 6",
  translationTag: "Environment"
}, {
  cat: "Cat 7",
  translationTag: "IT"
}, {
  cat: "Cat 8",
  translationTag: "ResearchAndDevelopment"
}, {
  cat: "Cat 9",
  translationTag: "LegalRequirements"
}];

So I'm iterating over the objects the following way:

  <div class="row" ng-repeat="cat in categories track by $index">
    <div class="col s12">
      <div class="col s4">
        {{cat.cat}}  - {{cat.translationTag}}
      </div>
      <div class="col s8">
        <textarea ng-model="ngmodelfield.[cat.translationTag]" class="materialize-textarea"></textarea>
      </div>
    </div>
  </div>

Now I want to link the first textarea to ngmodelfield.OccupationalSafety, the second to ngmodelfield.IndustrialSafety and so on.

But this doesn't seem to work as shown here: http://plnkr.co/edit/WKCLjzmLy1IrwEmQPMRH?p=preview

Shekhar Khairnar

Just change:

<div class="col s8">
    <textarea ng-model="ngmodelfield.[cat.translationTag]" class="materialize-textarea">{{cat.cat}}</textarea>
</div>

to:

<div class="col s8">
     <textarea ng-model="ngmodelfield[cat.translationTag]" class="materialize-textarea">{{cat.cat}}</textarea>
</div>

That is, remove the dot from ng-model="ngmodelfield.[cat.translationTag]".

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Delete Item from Array in Angular at Index value

From Dev

angular js autocomplete key value array

From Dev

Check if value in array in angular template?

From Dev

Find value in array then return true with Angular forEach

From Dev

Getters and Setters vs Oject key value pair

From Dev

Angular custom filter by array value

From Dev

Compare array value after sort angular js

From Dev

give random order to $http json oject through angular JS controller

From Dev

use pointer to single value as Array

From Dev

How to append the given value in array in angular js

From Dev

Parse JSON array in array and use key value

From Dev

How to check if a value is a property of an array in angular?

From Dev

Use return value of a function as a string in Angular 2

From Dev

Filtering array in Angular it is getting only the last value

From Dev

angular js autocomplete key value array

From Dev

Compare array value after sort angular js

From Dev

check existing object value in array angular JS

From Dev

Use Updated Value In Array

From Dev

Parse JSON array in array and use key value

From Dev

Angular selected option ignoring first array value

From Dev

Ionic / Angular, pass JSON/Array value as HTML

From Dev

Remove unchecked value from an array angular js

From Dev

Add dynamically value in array Angular 2

From Dev

Angular 2 : How to let *ngIf use value from array of *ngFor which includes it?

From Dev

Grabbing value from nested json array with Angular

From Dev

Angular 2 accessing value in an array

From Dev

How to use EOD as a array value

From Dev

Angular 4 All Input with Value to Array

From Dev

form array value changes angular

Related Related

HotTag

Archive