Created
February 25, 2014 20:51
-
-
Save mattlockyer/9217458 to your computer and use it in GitHub Desktop.
Angular Apply Helper for Controllers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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