Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to add a class to the component root element?

Except for adding the class in html.

I mean something like that:
In html

<my-component></my-component>

In js

angular.module('app').component('myComponent', {
  template: '<div class="inner-element">Inner element</div>',
  className: 'outer-element' <--- wanted property
});

This is how I want it to look after render:

<my-component class="outer-element"> <--- that's what I want to get
  <div class="inner-element">Inner element</div>
</my-component>
like image 659
through.a.haze Avatar asked Jul 05 '17 12:07

through.a.haze


1 Answers

You could specify controller that adds class on component init

controller: function($element) {
  this.$onInit = function() {
    $element.addClass('outer-element')
  };
}

But this kinda goes against encapsulation and such.

like image 134
Yury Tarabanko Avatar answered Nov 03 '22 01:11

Yury Tarabanko