0

There must be a more elegant way of doing this.

I'm simply; passing this boolean flag from the page markup through to the subcomponent:

<span *ngIf="flushToText">
    <span 
        class="icon flushToText" 
        [title]="tooltip" >
    </span> 
</span>
<span *ngIf="!flushToText">
    <span 
        class="icon" 
        [title]="tooltip">
    </span> 
</span>

Essentially, this says: if flushToText is TRUE, then add class flushToText.

(Here's the markup that invokes it:)

    <app-td-label 
            id="industry" 
            tooltip="Enter key words" 
            bold="true"
            flushToText="true">
    </app-td-label>

I tried ng-class, but I could not seem to get the right syntax. I tried every combination of quotes and brackets:

        ng-class="flushToText: flushToText"
        ng-class="'flushToText': flushToText"
        ng-class="{'flushToText': flushToText==true}"

etc.

0

2 Answers 2

1

There are a few issues with your implementation. The ng-class is an AngularJS(1.x) syntax and won't be applicable to Angular(2+).

The syntax in Angular has changed to:

<span 
  class="icon"
  [class.flushToText]="flushToText">
  {{ tooltip }}
</span>

Alternatively, you could also use this:

<span 
  class="icon"
  [ngClass]="{ 'flushToText': flushToText }">
  {{ tooltip }}
</span>

Here's a Working Sample StackBlitz for your ref.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. The second one is what I see it as the more 'standard' method.
0

To access class variable you need to property binding syntax of Angular

[class.class-name] = "classVariableName"

So in your case bind like below

[class.flushToText] = "flushToText"

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.