0

I have a loop where i display dynamically icons, the position of the icons are styled by css on style.css, but the classes name are actually an elements of json object.

The problem is how to use the value of the json element which is style in order to style the icons.

The *ngFor looks like this:

  <div *ngFor="let count of counters; let i = index"  class="{{count.style}} dispanserDiv ">
      <span class="dispLabel"> {{count.name }}</span>
    <img (click)="openStockModal(stockModal)" class="dispanser" src="../assets/icons/dispanserIcons/0.png">
  </div>

When i insepct to check the value,the desired classes are set whith the value as exactly as i want, but when i hard coded the classes it works fine

also i tried [ngClass] but not working, any help is appreciate.

6
  • Do you mean the value of the json element is a classname or a style like {'width': '100%,', height':'500px'}"? Commented Oct 25, 2018 at 19:44
  • @Igor Carvalho yes that what i meant Commented Oct 25, 2018 at 19:46
  • Did you try to use [ngStyle]? Commented Oct 25, 2018 at 19:48
  • @Igor Carvalho no, but does this attribute take a class name or a css code? Commented Oct 25, 2018 at 19:49
  • [ngStyle] can take a css code. use [ngClass] for a class name. Commented Oct 25, 2018 at 19:52

1 Answer 1

1

Well, after i opened the inspect element, and i hover over the tags i found on screen a title message with a direction arrow out of the height of the scree, so i changed the margin-top attr th icon appear again.

but i am pretty sure that when i set the class name without using the json element value, it display fine, but when i use the json element the icons appear at a different position, but i have no idea why this is happening. but it finally worked

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.