1

How would I go about targeting this model in the controller?

formData[$index].ID

This is not working -

$scope.getJob = function() {
        Employee.get({id: "" + $scope.formData[$index].ID}, function (data) {
            console.log(data);
        })
    }
0

1 Answer 1

1

You would actually inject the object or index from your template. Something like this:

<div ng-repeat="o in formData">
    <button ng-click="getJob($index)">Click me!</button>
</div>

and then in your code:

$scope.getJob = function(idx) {
    Employee.get({id: "" + $scope.formData[idx].ID}, function (data) {
        console.log(data);
    })
}

Alternatively, instead of injecting the index, you could inject the entire object:

<div ng-repeat="o in formData">
    <button ng-click="getJob(o)">Click me!</button>
</div>

and then in your code:

$scope.getJob = function(o) {
    Employee.get({id: o.ID}, function (data) {
        console.log(data);
    })
}
Sign up to request clarification or add additional context in comments.

1 Comment

I'm glad I could be of assistance @Dave!

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.