angularjs - Can a CSS class selector be applied to a component? -
i have following plunker uses ui-router , angular's 1.6x new component feature.
the state 'userregister' becomes active initialises 'userregister' component. component injects new <user-register/> <ui-view> injects html contents of ng-template script block, working fine.
the final dom ends being:
<ui-view class="ng-scope"> <user-register class="ng-scope ng-isolate-scope"> <h1 class="header">create account</h1> </user-register> </ui-view> however, cannot find way add css class selector <user-register/> tag.
e.g. using class selector called .example i'd achieve following:
<user-register class="example ng-scope ng-isolate-scope">...<user-register/>
any ideas please?
sure wrap template on div , put class there.
if don't want it, can inject $element , use $postlink function add class need:
.component('userregister', { templateurl: '/views/user-register', controller: function($element) { this.$postlink = function() { $element.addclass('example'); } } }) here working plunker:
https://plnkr.co/edit/vuwu8l9vqrgjrgnxity2?p=preview
final dom:
<user-register class="ng-scope ng-isolate-scope example"> <h1 class="header">create account</h1> </user-register>
Comments
Post a Comment