Since you are manually creating $injector , you need to somehow say where to get $rootElement . One way to do this is to define a built-in module:
angular.injector(['ng', function($provide){ var $rootElement = angular.element(document.querySelector('body')); $provide.value('$rootElement', $rootElement); }]).invoke(function ($injector){ var localRootElement = $injector.get('$rootElement'); });
I updated your plunker accordingly.
As for the way to avoid using $timeout , a detailed answer can be found in:
$ Digest error prevention is already done when calling $ scope. $ apply () .
In short, you can do a simple check (which doesn't mean you should):
if(!$scope.$$phase) { //$digest or $apply }
See the related answer for more details.
source share