如何操纵样式指令在AngularJS? [英] How to manipulate styles of directive in AngularJS?

查看:97
本文介绍了如何操纵样式指令在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>

除了这个我想能够操纵中的所有元素的风格我
成分(我的标签内的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆