[英]Angular directive with “E”, cannot addClass
最近學習angularjs,我對指令有疑問。 當我創建“ E”時,嘗試在其上添加一個類調用“ panel”(它將背景色設置為紅色),它不起作用,但是當我創建“ A”時,它實際上起作用。 有人知道為什么會發生嗎?
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.name = 'world';
});
app.directive("pop", function() {
return {
restrict: 'E',
template: '<div button>' +
'popup window, hello' +
'</div>',
link: function(scope, element, attrs) {
test(element);
}
}
});
app.directive("button", function() {
return {
restrict: "A",
link: function(scope, element, attrs) {
// test(element);
}
}
})
function test(element) {
element.bind("mouseenter", function() {
element.addClass("panel");
});
}
如果添加position:absolute;
到.panel的CSS,它可以按預期工作,請參閱下面的plunkr。 這里的問題是自定義標記元素的默認樣式,而不是與angular有關的任何樣式。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.