[英]How to set CSS styles within Link function of Angular directive
I'm attempting to set CSS styles on a certain class within a custom Angular directive when it is clicked. 我在单击自定义Angular指令时尝试在某个类上设置CSS样式。 I want to accomplish this (and any other DOM manipulation) within the Link function.
我想在Link函数中完成这个(以及任何其他DOM操作)。 Below is what I have so far, but I'm getting an
address.on is not a function
error. 下面是我到目前为止,但我得到一个
address.on is not a function
错误。 How would I properly set the CSS -webkit-filter: none
on the blur
class when blur
class elements are clicked? 当单击
blur
类元素时,如何在blur
类上正确设置CSS -webkit-filter: none
?
function link(scope, element, attributes) {
var address = element[0].getElementsByClassName('blur');
address.on('click', function() {
address.css({'-webkit-filter': 'none'});
});
}
address
is a DOM element. address
是一个DOM元素。 You need to wrap it in angular.element
to turn it into a jqLite object: 您需要将其包装在
angular.element
以将其转换为jqLite对象:
function link(scope, element, attributes) {
var address = angular.element(element[0].getElementsByClassName('blur'));
address.on('click', function() {
address.css({'-webkit-filter': 'none'});
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.