javascript - Angular using $index in ng-model -


I have the following loops in which I am trying to increase multiple fields based on the array index through the loop each time .

  & lt; Div class = "individualwrapper" ng-repeat = "[n] in [] category: 4" & gt; & Lt; Div class = "iconimage" & gt; & Lt; / Div & gt; & Lt; Div class = "icontext" & gt; & Lt; P & gt; Imagine that you are in the health care facility. & Lt; / P & gt; & Lt; P & gt; What do you really think of this symbol? & Lt; / P & gt; & Lt; Textarea type = "text" name = "interpretation_1" ng-model = "interpretation_1" ng-required = "true" & gt; & Lt; / Textarea & gt; & Lt; P & gt; What action will you take in response to this symbol? & Lt; / P & gt; & Lt; Textarea type = "text" name = "action_1" ng-model = "action_1" ng-required = "true" & gt; & Lt; / Textarea & gt; & Lt; / Div & gt; & Lt; / Div & gt;  

I want to do something like this "

  ng-model =" interpret_ {{$ index + 1}} " 

Angle is not presenting this value? What would be the best way to add such logic to the MG-model area?

An invalid expression is created with the use of interpolation with this NG-model expression. You must give a property name there. You can use the bracket and use the bracket notation.

In either your controller:

  $ scope.interpretation = {}  < / Pre> 

and use it in your view:

  ng-model = "interpretation [$ index + 1]"  

Demo

< Div class = "snippet-code snippet-current-hidden">
  angular Module ('app', []). Controller ('ctrl', function ($ scope) {$ scope.interpretation = {}; $ Scope.actions = {};});  
  & lt; Script src = "https://ajax.googleapis.com/ajax/ libs/ AngularJS / 1.3.8 / angular.min.js" & gt; & Lt; / Script & gt; & Lt; Div ng-app = "app" ng-controller = "ctrl" & gt; {{Definition}} {{actions}} & lt; Div class = "individualwrapper" ng-repeat = "n [1,2,3,4]" & gt; & Lt; Div class = "iconimage" & gt; & Lt; / Div & gt; & Lt; Div class = "icontext" & gt; & Lt; P & gt; Imagine that you are in the health care facility. & Lt; / P & gt; & Lt; P & gt; What do you really think of this symbol? & Lt; / P & gt; & Lt; Textarea type = "text" ng-attr-name = "interpretation {{$ index} 1}" ng-model = "interpretation [$ index + 1]" ng-required = "true" & gt; & Lt; / Text field & gt; & Lt; P & gt; What action will you take in response to this symbol? & Lt; / P & gt; & Lt; Textarea type = "text" name = "verb {{$ index + 1}}" ng-model = "verb [$ index + 1]" ng-required = "true" & gt; & Lt; / Textarea & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt;  


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -