0

I have this in html :

  <ul class="operators">
            <li>Operators: </li>
            <li *ngFor="let operator of operators" [ngClass]="{'bold' :uS.getUserCode() == operator }"><i
                class="fa fa-at"></i>
              {{userService.getName(operator)}}</li>
          </ul>

On enter i insert in array opertaros new operator.

But i want to check if uS.getUserCode() == operator to add class 'bold'. uS.getUserCode() is a @Injectable() service that is loaded on start of app and i imported it in constructor.

Any suggestion how can i achive this?

3
  • 2
    Please provide a minimal reproducible example of your issue Commented Jun 25, 2019 at 9:30
  • What is operator? Also did you mean === instead of ==? Commented Jun 25, 2019 at 9:31
  • operator is user code : string Commented Jun 25, 2019 at 9:33

1 Answer 1

2

Make sure that uSis injected as public in constructor as

constructor(public uS: UsService) {}

this will let us us uS in view so you can check your condition in ngFor.

[ngClass]="{'bold': uS.getUserCode() === operator}"

i assume getUserCode() returns objects and you're comparing it to operator. It is suggested to be compared by some property in order to return true or false instead of comparing objects like this.

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.