Search code examples
angularjsscopeangularjs-scope

AngularJS: How do you pass in element id with multiple scope parameters in the id string?


I have elements in an ng-repeat loop with multiple other loops on the page. The loops look like:

<div ng-repeat="a in MyArray"> ....

For this reason the elements are all classified with id's such as:

<input id="{{a.Id}}{{a.Name}}{{a.Value}}"....

In the same input variable, I have an ng-class parameter that calls a function that passes the id to the js.

How would I go about passing in such an id?

I know that theoretically, it would be passed in like this:

ng-class="myfunction({{a.Id}}{{a.Name}}{{a.Value}})"

If the Id was 15, Name was "Broom" and Value was 5, how can I pass into the ng=class function such a variable:

ng-class=myfunction("15Broom5")

Solution

  • In the same input field just change as this:

    <input type="text" id="{'a':$scope.Id,'a'.$scope.Name,'a':$scope.Value}"/>