Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save eduardoreche/6302db667852da0b2485 to your computer and use it in GitHub Desktop.
Save eduardoreche/6302db667852da0b2485 to your computer and use it in GitHub Desktop.
Callback call in angular ng-click
<div ng-app="testApp">
<div ng-controller="myCtrl">
<a href="" ng-click="fA()">Function A</a> <br>
<a href="" ng-click="fB('some text', _callback, 'callback text param')">Function B</a>
<br>
{{text}}
</div>
</div>
angular.module('testApp', [])
.controller('myCtrl', function($scope) {
$scope._callback = function(text) {
return text;
}
$scope.fA = function(){
$scope.text = 'this is function A' ;
}
$scope.fB = function(text, callback, callback_param) {
$scope.text = 'this is function B '+ callback(callback_param) ;
}
$scope.text = '';
});
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.14/angular.min.js"></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment