Angularjs Callback Example - Jquery

How to use callback function in angularjs?

Snippet Code

Rate this page :
  [ 0 votes]

Callback is asynchronous code which is used to return a message after execution. Success method in angularjs is used to display a callback message and display the output in console.log. Here, the sample code for angularjs callback is given below.

<html ng-app="my-app"> <head> <script src="//"></script> <script src="//"></script> <script> var app = angular.module('my-app', [], function () { }) app.controller('AppController', function ($scope) { $scope.callbackFunctionInController = function(){ console.log('do something') }; $scope.$watch('somedata', function(data){ console.log('controller', data); }, true); }); app.directive('mySave', function($http, $parse) { return { scope: { data: '=mySaveData', callback: 'ampmySaveCallback' }, link: function(scope, element, attrs) { $http.get('data.json').success(function(data){ console.log('data', data); = data; scope.callback(); }); } }; }); </script> </head> <body ng-controller="AppController"> <div my-save my-save-data="somedata"></div> Check Console For Callback Status.. </body> </html> data.json: ------------ { "name": "hscripts", "date": "15 Oct 2015" }


Ask Questions

Ask Question