Tôi đã viết bài kiểm tra đối với một số thành phần kiễu góc, sử dụng một cú pháp mà tôi tìm thấy trên google một lúc trước:ý nghĩa của dấu gạch trên thuốc chích ở góc
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();
});
});
Câu hỏi của tôi là cụ thể về việc tiêm _$compile_
. Nó khác với chỉ $compile
. Tại sao tôi cần phải làm theo cách này? Tại sao biên dịch $ được định nghĩa lại, tại sao tôi không thể biên dịch đơn giản với một biên dịch $ tôi nạp?
https://docs.angularjs.org/api/ngMock/function/angular.mock.inject#resolving-references-underscore-wrapping- – gregjhogan