angularjs - meaning of underscores on injectables in angular -


i've been writing tests angular components, using syntax found on google while ago:

 describe('directive: mydir', function () {      beforeeach(module('myapp'));      beforeeach(module('app/views/my_template.html'));      beforeeach(inject(function ($rootscope, _$compile_, $templatecache) {          $templatecache.put('views/my_template.html', $templatecache.get('app/views/my_template.html'));           var scope, $compile;          scope = $rootscope;          $compile = _$compile_;          element = angular.element("<div my-dir class='my-dir'></div>");      }));       it('does things', function () {          $compile(element)(scope);          scope.$digest();      });  }); 

my question injection of _$compile_. how different $compile. why need way? why $compile redefined, why can't compile $compile inject?

from angular official tutorial (test section):

the injector ignores leading , trailing underscores here (i.e. $httpbackend). allows inject service attach variable same name service.

in example, rename variable $compile as, say, compile , remove underscores parameter name. in fact, did scope $rootscope remained underscore-free.

personally keep name of angular built-in services in tests can spotted while skimming through code.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -