0

New to Angular JS, trying to access the click event using ng-click.

HTML:

<button ng-click="selectNav($event)">Click</button>

JS:

angular.module('app').controller('ctrl', function(){ 
    $scope.selectNav = function($event){ 
       console.log($event); 
    } 
});

On click of the button, its not giving the value of $event. Can any one let me know where am I going wrong.

6
  • have you tried putting alert($event);? Commented Jun 19, 2014 at 5:42
  • derp... he is logging it to the console... Commented Jun 19, 2014 at 5:43
  • seems fine jsfiddle.net/arunpjohny/Ds7z5/1 - which angular version is used Commented Jun 19, 2014 at 5:43
  • @BhushanKawadkar: Yes tried but no action is happening. Commented Jun 19, 2014 at 5:45
  • I tried jsfiddle share by @ArunPJohny, and it seems fine to me also. Commented Jun 19, 2014 at 5:45

2 Answers 2

2

I've noticed you didn't pass $scope to the controller. try to fix that maybe

angular.module('app').controller('ctrl', function($scope){ 
    $scope.selectNav = function($event){ 
       console.log($event); 
    } 
});
Sign up to request clarification or add additional context in comments.

Comments

0

problem with $scope in your controller.

angular.module('app').controller('ctrl',['$scope', function($scope){ 
    $scope.selectNav = function($event){ 
       console.log($event); 
    } 
}]);

Comments

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.