2017-08-04 51 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> 

做這種方式。