如何在 angular js 中的函数内绑定 $index

How to bind $index inside a function in angular js

我用 angular js ng-repeat

重复了 div
<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

如何获取以{{ $index }}百分比作为ID的输入类型的准确值

我已经写了 $index 以具有唯一标识,因为文本框将重复多次。

请帮忙,提前致谢:)

将索引传递给 ng-click 函数时删除表达式。

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

试试这个

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

在 HTML 中验证此值是否正确填充。

同样适用于按钮

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

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

这样做。