0

I have repeated a div by using angular 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>

So, when I click on submit button submitted method will be called with input feilds id passed as parameter in it,

Please take a look at the js code below :

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

Now when I use the parameter and print its value I'm getting error, Saying

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

How should I get the exact value of the input type with {{ $index }}percentage as ID

I have written $index to have the unique id as the text box will be repeated many times.

Please help, thanks in advance :)

3 Answers 3

1

remove the expressions when you pass an index to a ng-click function.

ng-click="submitted($index + 'fromHours')">
Sign up to request clarification or add additional context in comments.

1 Comment

@Harish nice. make sure to check as right answer if this helped
1

Try this

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

verify in the HTML if this value is properly populated.

Same is applicable to button as well

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

Comments

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

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

Do it this way.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.