Jose
Jose

Reputation: 1239

AngularJS Access $scope in function

I execute the following function when a page is executed:

$scope.displayTags = function(Id) {
    $scope.toogleSelectionBlocs = function selectionB(b) {
          // I have a checkbox to check...
    }

   $scope.showHello() {
       console.log("HELLO WORLD!");
   }
}

Then I have an other checkbox: (same controller but other function)

$scope.checkClick = function(){
    if($scope.mycheckbox == true){
        $scope.showHello();
    }
}

I have the following error:

TypeError: undefined is not a function
    at Scope.$scope.checkClick (....)

How I can fix it?

Thanks for your help!

Upvotes: 1

Views: 70

Answers (2)

Bazinga
Bazinga

Reputation: 11234

You have a mistake in your function thats should be:

$scope.showHello = function() {
     console.log("HELLO WORLD!");
 }

and another thing why do you write the function inside another function, you should move the $scope.showHello to the outside of the $scope.displayTags

Upvotes: 1

smartbart24
smartbart24

Reputation: 524

1) $scope.showHello is missing the "=function(params){ .... } " part. (That should solve the problem you asked for)

2) Can you post more of your controller code to make clear what you are actually trying to do - the code looks a bit strange to me. (e.g. the "= function selectionB(b) {" part.

Upvotes: 2

Related Questions