In the examples of attribute directives (i.e., directives for adding appearance / behavior), we have a fairly simple style setting for the host element. For example,
import {Directive, ElementRef } from 'angular2/core'; @Directive({ selector: '[myHighlight]' }) export class HighlightDirective { constructor(element) { element.nativeElement.style.backgroundColor = 'yellow'; } static get parameters(){ return [[ElementRef]]; }
Instead of setting a style, can I use styles instead? eg.
@Directive({ selector: '[myHighlight]', styles: [':host { background-color: yellow; }'] })
This does not work for me?
I am doing something more complex, which has led to a lot of monolithic code, setting a lot of styles, using AnimationBuilder, etc. etc., it seems to me that it would be much better to separate this from classes and animations in CSS.
ViewEncapsulation = emulated / default, if this is important?
angular angular2-directives
ct5845 Mar 10 '16 at 11:38 2016-03-10 11:38
source share