I've been writing tests for some Angular components, using a syntax that I found on google a 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 is specifically about the injection of _$compile_
. How is it different from just $compile
. Why would I need to do it this way? Why does $compile get redefined, why can't I simply compile with a $compile I inject?