如何在 AngularJS 中操作指令样式? [英] How to manipulate styles of directive in AngularJS?
本文介绍了如何在 AngularJS 中操作指令样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 AngularJS 和 AngularJS 指令编写一个组件.
I'm writing a component using AngularJS and AngularJS directives.
我正在做这样的事情:
var MyApp = angular.module('MyApp', []);
MyApp.directive('myTag', function() {
return { /* Some logic here*/ }
});
我希望能够更改组件的样式(使用 CSS),如下所示:
I want to be able to change style of my component (using CSS), something like this:
<my-tag class="MyClass"></my-tag>
除此之外,我希望能够在我的内部操作所有元素样式组件(my-tag 内的 HTML 标记).
Besides this I want to be able to manipulate all elements style inside my component (HTML markup inside of my-tag).
对于如何使用 AngularJS 操作自定义标签的样式属性,您有什么建议或有用的示例吗?
Do you have any advice or useful examples how to manipulate the style properties of custom tags using AngularJS?
推荐答案
这应该可以解决问题.
var MyApp = angular.module('MyApp', []);
MyApp.directive('myTag', function() {
return {
link: function(scope, element, attributes){
element.addClass('MyClass');
}
}
});
这篇关于如何在 AngularJS 中操作指令样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文