Last active
August 29, 2015 13:58
-
-
Save demetriusnunes/9964749 to your computer and use it in GitHub Desktop.
Extending $scope
This file contains 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
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