AngularJS/Jasmine/Karma无法获取ng include指令的angular.element
我有一个这样加载的模板:AngularJS/Jasmine/Karma无法获取ng include指令的angular.element,angularjs,unit-testing,angularjs-directive,jasmine,angularjs-ng-include,Angularjs,Unit Testing,Angularjs Directive,Jasmine,Angularjs Ng Include,我有一个这样加载的模板: <li ng-repeat="favorite in favorites" ng-include="'templates/directives/favoriteContactCardDirective.html'" class="list-unit"></li> 但似乎控制器除了加载模板之外什么也不做,所以决定将其删除并使用ng include。但现在这不起作用了。 因此,问题是: 是否有可能使这种方法(ng包括但不包括控制器)起作用 如果是,
<li ng-repeat="favorite in favorites" ng-include="'templates/directives/favoriteContactCardDirective.html'" class="list-unit"></li>
但似乎控制器除了加载模板之外什么也不做,所以决定将其删除并使用ng include。但现在这不起作用了。
因此,问题是:
我不明白你想在这里实现什么。为什么您认为编译
会将其转换为其他内容或加载其他模板或其他内容?这是一个纯静态的HTML,没有使用任何指令。我不明白你想在这里实现什么。为什么您认为编译
会将其转换为其他内容或加载其他模板或其他内容?它是纯静态的HTML,不使用任何指令。
function getCompiledElement(tag){
var compiledElement = compile(angular.element('<div class="list-unit"></div>'))(scope);
scope.$digest();
return compiledElement;
}
'use strict';
describe('Directive: FavoriteContactCardDirective', function () {
var jasmine.getFixtures().fixturesPath = "base/test/mock/";
var compile,
scope,
directiveElem;
beforeEach(function(){
module('feStringerApp');
module('karmaTemplates');
inject(function(_$compile_, _$rootScope_){
compile = _$compile_;
scope = _$rootScope_.$new();
// ...
});
directiveElem = getCompiledElement();
});
function getCompiledElement(tag){
var compiledElement = compile(angular.element('<div class="list-unit"></div>'))(scope);
scope.$digest();
return compiledElement;
}
it('should have the right structure', inject(function(){
expect(directiveElem).toExist();
var accountCard = angular.element(directiveElem[0]);
console.log('accountCard', accountCard);
}));
});
'accountCard', {
0: <div class="list-unit ng-scope"></div>,
context: <div class="list-unit ng-scope"></div>,
length: 1
}
angular.module('feStringerApp').directive('feFavoritesContactCard', function () {
return {
restrict: 'E',
replace: true,
templateUrl: 'templates/directives/favoriteContactCardDirective.html'
};
});