Within my module's config, I have extended $rootScope by adding a function called safeApply
.
$provide.decorator('$rootScope', ['$delegate', function($delegate) {
$delegate.safeApply = function(fn) {
...
};
return $delegate;
}
]);
Is it appropriate to access it like this:
$scope.$root.safeApply();
Or do I need to inject $rootScope
and then call it?
Can I incorporate this method into the prototype of $rootScope
so that it is inherited by all $scope
? If so, how can I achieve this?
Edit
Adding on to khanh's response below, it may be helpful to provide additional information. The purpose of the safeApply method is to manually trigger a digest cycle. The concept of decorating the $rootScope was inspired by this article. It involves enhancing functionality rather than just decorating a method, making it universally accessible within the scope of directives and controllers.