4

I'm trying to use angular2 @Input directive to get a CSS class from another component. Say I have the following:

<custom-component ngClass="xClass"> </custom-component>

I have "xClass" in the current component css file, and I want to pass this class as input to the custom-component using @Input like so:

@Input('dac-class') private class: CSS //not sure about this;

is that possible in one way or another?

1

1 Answer 1

0
@Input('dac-class') private Klass: string

The word class is reserved , so you cannot use it as an alias in javascript or typescript, also , it's always nicer to have input with the same name as the alias .:

@Input('dac-class') private decClass: string

and then you'd use it :

 <custom-component dac-class="someCssClass"  ngClass="xClass"> </custom-component>
Sign up to request clarification or add additional context in comments.

5 Comments

When you say dac-class="someCssClass" this someCssClass is read as string.
class should be string, shouldn't it ? if you want variable , just pass [dac-class]="someCssClass"
Yes, this would be true if I'm reading this input as object from the .ts file, but this isn't the case. I want to read the css class object with its properties from the .css file
What do you mean from .css file ? doesn't make any sense, show us some of your code base
.xClass { width: 20px; height: 30px; } this class is in the .css file, I want to pass it to another component as it is

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.