Skip to content

Instantly share code, notes, and snippets.

@demetriusnunes
Last active August 29, 2015 13:58
Show Gist options
  • Save demetriusnunes/9964749 to your computer and use it in GitHub Desktop.
Save demetriusnunes/9964749 to your computer and use it in GitHub Desktop.
Extending $scope
angular.module("myApp").run(function ($rootScope) {
var proto = Object.getPrototypeOf($rootScope);
angular.extend(proto, {
$waitFor: function (expression, fn) {
var un = this.$watch(expression, function (value) {
if (value === undefined) return;
un();
return fn(value);
});
}
});
});
// example of usage in the controller
$scope.$waitFor('user', function (user) {
$scope.userName = user.name;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment