1

I have a card component in my app. Based off what type of card it is there is a different style that needs to be applied to the root element of the template. When I do this:

<card class="card-type-class"></card>

My html ends up looking like this:

<card class="card-type-class">
    <div class="other-constant-classes">
        content of my card
    </div>
</card>

Instead of like this:

<card>
    <div class="other-constant-classes card-type-class">
        content of my card
    </div>
</card>

Is there anyway to apply classes from the selector to the root element of the component template?

***Sorry if this has been asked, I had a hard time figuring out how to search for that question...

2
  • would an attribute based selector work ? selector: '[tn-labelfor]', usage <label tn-labelfor change stuff this.renderer.setElementAttribute(this.elementRef.nativeElement,'class','my class'); Commented May 15, 2017 at 16:43
  • angular.io/docs/ts/latest/guide/attribute-directives.html Commented May 15, 2017 at 16:45

1 Answer 1

2

You could always pass in the class as a string:

<card [myClass]="'card-type-class'"></card>

Then in the lower component:

@Input() myClass: string;

And the HTML:

<div class="other-constant-classes {{myClass}}">
    content of my card
</div>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.