我有一个angularjs组件,
HTML模板
<div id="panel" class="hide-div">
<div id="viewPort" class="hide-div">
...
</div>
</div>
JS
var myController = function() {
var ctrl=this;
ctrl.$onchanges = function() {
}
var source = $("#viewport");
var target = $("#panel");
var observer = new MutationObserver(function() {
target.toggleClass("hide-div", source.hasClass("hide-div"));
});
observer.observe($("#viewport")[0], {attributes: true});
}
var config = {
controller: [myController],
templateUrl: "temp/abc.html",
bindings: {
id: "<",
name: "<"
}
};
directives.component("myComponent", config);
这里我有MutationObserver
通过观察其他元素属性
Jasmine脚本 我在这里为所有测试用例设置脚本
beforeEach(inject(function($rootScope, $compile, _$componentController_, ...){
$templateCache.put("temp/abc.html", "<div><div id='panel' /><div id='viewport' /></div>");
rootScope = $rootScope;
scope = $rootScope.$new();
$componentController = _$componentController_;
element = angular.element("<my-component></my-component>");
element = $compile(element)(scope);
ctrl = $componentController("myComponent", null, componentBining);
}));
这里我收到以下错误,
NotFoundError: NotFoundError: DOM Exception 8 in temp/abc.html observe@[native code]