Skip to content

Instantly share code, notes, and snippets.

@mattlockyer
Created February 25, 2014 20:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattlockyer/9217458 to your computer and use it in GitHub Desktop.
Save mattlockyer/9217458 to your computer and use it in GitHub Desktop.
Angular Apply Helper for Controllers
/*
This gist is intended to be included in controllers and provides an easy way to ensure data is applied
The function: func will be executed within an existing digest $$phase or call $scope.$apply and invoke one
*/
var apply = function(func, callback) {
if(!$scope.$$phase) {
$scope.$apply(function() {
func();
if (callback) callback();
});
} else {
func();
if (callback) callback();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment