2017-08-04 23 views
0

我已经重复一个div通过角JS ng-repeat

<div ng-repeat="exampleData in example"> 
<input type="text" id="{{ $index }}percentage"/> 
<button type="btn btn-success" ng-click="submitted('{{ $index }}fromHours')">Submit</button> 
</div> 

所以,当我点击提交按钮提交方法将输入精密组件ID通过为被称为参数吧,

请看看下面的JS代码:

$scope.submitted = function(percentage){ 
console.log($('#'+percentage).val()); 
} 

现在,当我使用的参数,并打印出它的价值我得到的错误,说

Syntax error, unrecognized expression: #{{ $index }}percentage 

我应该如何获得输入类型与{{$指数}}百分比ID的确切值

我已经写$指数具有独特的ID作为文本框将被重复很多倍。

请帮帮忙,在此先感谢:)

回答

1

当你传递一个索引来ng-click功能删除表达式。

ng-click="submitted($index + 'fromHours')"> 
+0

感谢它现在的工作:) – Harish

+0

@Harish不错。如果这有帮助,一定要检查正确的答案 –

1

试试这个

<input type="text" ng-id="$index + 'percentage'"/> 

在HTML验证如果此值正确填充。

同样适用于按钮以及

<button type="btn btn-success" ng-click="submitted($index + 'fromHours')"> 
1
<input type="text" ng-id="$index + 'percentage'"/> 

<button type="btn btn-success" ng-click="submitted('$index + 'fromHours')">Submit</button> 

做这种方式。