1

I have the following code:

$scope.someVar = function(parameter){
if ($scope.parameter[this.$index].toCheck == 'false') {
  $scope.anotherVar= '.'
} else {
  $scope.anotherVar = ', to check with you if it has worked.'
}
};

When I then call in HTML:

<a href="#" ng-repeat="test in tests" ng-click="template(emails)">Link</a>

I get the following error:

TypeError: Cannot read property '0' of undefined
at ChildScope.$scope.someVar (mainController.js:80)

What am I doing wrong?

Thank you in advance for your suggestions.

1
  • where does $scope.parameter comes from? do you want it to be parameter instead? Because it's not an array, so you can't take an index (property) of it with [this.index]. Is this.index even an number, or a string? Commented Apr 27, 2018 at 8:07

1 Answer 1

1

Error clearly states that $scope.parameter[$index] is undefined, and you're trying to access toCheck property from it. It seems like you you are expecting parameters variable in $scope. Rather you should refer to function parameter parameter

if ($scope.parameter[this.$index].toCheck == 'false') {

should be

if (parameter[this.$index].toCheck == 'false') {
Sign up to request clarification or add additional context in comments.

1 Comment

That did it. Thank you very much @PankajParkar :)

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.