>我有一个带有隔离范围的指令,我在其中传递绑定属性
"="
:
.directive('drawCircle',function (){
return {
restrict:'A',
replace:false,
scope:{
point:'=',
},
template:' <circle '+
'ng-attr-cx="{{point[0]}}" ng-attr-cy="{{point[1]}}" '+
'r="3" fill="purple" />'
};
});
我使用它:
<g draw-circle point="[22,33]">
它在浏览器中工作正常,但 karma 抛出:
Error: [$compile:multidir] Multiple directives [drawCircle (module: myApp), drawCircle (module: myApp)]
asking for new/isolated scope on: <g draw-circle="" point="p">
下面是创建错误的单元测试:
describe('directives testing', function() {
var element, scope, compiled;
beforeEach(module('draw.path'));
describe('draw-single-point directive',function(){
beforeEach(inject(function($rootScope,$compile){
scope = $rootScope.$new();
element = angular.element('<g draw-circle point="p" ></g>');
compiled = $compile(element);
scope.p=[110,11];
compiled(scope);
scope.$digest();
}));
});
业力为什么抱怨?
这是您面临的可能问题
您的指令drawCircle
被定义/加载了两次,如果发生这种情况,这就是您会遇到的确切错误 - 检查该笔:http://codepen.io/maurycyg/pen/pgWyEy?editors=101
我认为您的测试代码或指令没有任何问题,甚至将该指令与ng-repeat一起使用都没有,所以我建议检查KARMA配置,也许您加载指令两次