简体   繁体   English

如何在Angular指令的Link函数中设置CSS样式

[英]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以将其转换为jqLit​​e对象:

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.

相关问题 为什么“this”为null,在Angular Directive中的link函数中? - Why is “this” null, in the link function within an Angular Directive? 如何在角度指令的链接函数中定义角度指令? - How to define an angular directive inside an angular directive's link function? 如何将$ q传递给angular指令链接函数? - How to pass $q to angular directive link function? 如何在角度指令的链接函数中传递值 - How to pass value in link function of a angular directive 如何在Angular指令中将参数传递给函数? - How to pass parameters to a function within an Angular directive? 链接功能和控制器功能如何在角度指令中共享知识? - How can a link function and controller function share knowledge in an angular directive? 将角度指令链接功能作为预链接? - Make angular directive link function as pre link? 如何在指令链接函数中对Angular routeChangeSuccess进行单元测试? - How to unit test Angular routeChangeSuccess in directive link function? 角度:指令:如何通过要求表格和控制器链接功能 - Angular: Directive: How to pass require form AND controller to link function Angular指令链接函数中的作用域是否与角度指令控制器中的$ scope相同? - Is the scope in an Angular directive link function the same $scope in an angular directive controller?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM