AngularJS angular.noop


Example

The angular.noop is a function that performs no operations, you pass angular.noop when you need to provide a function argument that will do nothing.

angular.noop()

A common use for angular.noop can be to provide an empty callback to a function that will otherwise throw an error when something else than a function is passed to it.

Example:

$scope.onSomeChange = function(model, callback) {
    updateTheModel(model);
    if (angular.isFunction(callback)) {
        callback();
    } else {
        throw new Error("error: callback is not a function!");
    }
};

$scope.onSomeChange(42, function() {console.log("hello callback")});
// will update the model and print 'hello callback'
$scope.onSomeChange(42, angular.noop);
// will update the model

Additional examples:

angular.noop() // undefined
angular.isFunction(angular.noop) // true