Serge Inácio
Serge Inácio

Reputation: 1382

Angularjs function with parameter

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.

Upvotes: 1

Views: 66

Answers (1)

Pankaj Parkar
Pankaj Parkar

Reputation: 136164

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') {

Upvotes: 1

Related Questions