Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/410.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript ng模型中使用$index的角度_Javascript_Html_Angularjs_Angularjs Ng Model - Fatal编程技术网

Javascript ng模型中使用$index的角度

Javascript ng模型中使用$index的角度,javascript,html,angularjs,angularjs-ng-model,Javascript,Html,Angularjs,Angularjs Ng Model,在下面的循环中,每次通过循环时,我都试图根据数组索引增加几个字段 <div class="individualwrapper" ng-repeat="n in [] | range:4"> <div class="iconimage"></div> <div class="icontext"> <p>Imagine that you are in a health care facility.</p>

在下面的循环中,每次通过循环时,我都试图根据数组索引增加几个字段

<div class="individualwrapper" ng-repeat="n in [] | range:4">
  <div class="iconimage"></div>
  <div class="icontext">
    <p>Imagine that you are in a health care facility.</p> 
    <p>Exactly what do you think this symbol means?</p>
    <textarea type="text" name="interpretation_1" ng-model="interpretation_1" ng-required="true"></textarea>
    <p>What action you would take in response to this symbol?</p>
    <textarea type="text" name="action_1" ng-model="action_1" ng-required="true"></textarea>  
  </div>
</div>

但是Angular没有呈现该值吗?在mg模型字段中添加此类逻辑的最佳方法是什么?

使用插值和ng模型表达式时,它将成为无效表达式。您需要在此处提供属性名称。相反,您可以使用对象并使用括号表示法

i、 e在控制器中:

$scope.interpretation = {};
在您看来,将其用作:

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

angular.module('app',[]).controller('ctrl',function($scope){
$scope.expansion={};
$scope.actions={};
});

{{解释}}{{动作}
假设你在一个医疗机构

你认为这个符号到底是什么意思

您将对此符号采取什么行动


检查此项以供参考:我似乎无法将括号符号解析到值中,这可能与的重复。ng model=“expression[$index+1]”以html以及我尝试过的其他范围值呈现。对我很有用。您使用的是什么版本的angular?请参阅在答案中内联编辑的演示。而且,您需要在交给控制器之前定义对象,这样您就不会一直更新子作用域上的属性,因为它似乎仍然不起作用。chrome inspector中的代码片段仍然显示未插入的{}符号。我用的是angular 1.3,你说的是
value
attribute吗?如果是这样的话#1)纯html中的value属性仅用于指定默认值,#2)只需输入
,然后输入,您将不会看到值或任何内容。使用angular时,更新的是value属性,而不是属性#3)不必担心DOM,只需担心ng模型和视图模型绑定,让angular按需要管理DOM,这不是使用angular方式的目的吗。
ng-model="interpretation[$index + 1]"