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
Post a Comment