I try to make change table data value positive and negative based on condition. Is there any possibility to make it with [ngClass]. i can not get it this way. any idea?
I have tried your code buddy and its working fine for me. i have tried like this
<table>
<tr *ngFor="let thumb of thumbnails" >
<td [ngClass]="{'positive': thumb.id > 5, 'negative': thumb.id < 5}">{{thumb.src}}</td>
</table>
i found one space between ngClass and = ,i am not sure but its may be because of that you getting this issue.
Try it by replacing the greater than(>) and Less than (<) with > and < , i am not sure but sometimes html dont understand < & > sign, since they used for both in HTML for tags and in scripting for comparing…
I would put a “market” value into each element in the controller and populate it with all the markets, which would eliminate the unwieldy wall of *ngIfs based off the index.
Are you sure you want to be checking +/- of Last instead of Change? That seems weird, because none of these commodities should ever close below 0, if I understand the app domain.
How are you storing these values in the controller? If they’re really the exact string values shown in your screenshot, then I think you might be being bit by JavaScript’s arcane value conversion rules refusing to convert what you think of as a number into one, due to the use of a comma as a decimal point:
My database update every 10 seconds and i don’t need to check ‘Last’ for positive and negative i want to implement some more in conditional way. For positive and negative i just want for ‘Changing’ because those values goes up and down.
I don’t understand what you mean for storing values in controller my application updates every 10 seconds when datababse updated. i do not store any values.
I would appreciated if you give some more suggestions. sorry if i understand wrong.
Inside the subscription where you assign to this.ghboil you could add additional market properties to each GbhOilList entry so that the template doesn’t have to have such fragile reliance on array indices.
I’m asking what GbhOilList looks like inside. Are its values that you are trying to treat as numeric numbers? Are they strings? Are they strings using commas as decimal separators? If so, JavaScript can’t natively convert them to numbers. You will have to do that yourself or use a library like numeral.js. JavaScript natively only accepts periods as decimal points, not commas.
i don’t need to check ‘Last’ for positive and negative
Well, you are doing just that in the sample you posted:
Are they really numbers as they come from ghboil? I’m still hung up on the use of commas as decimal separators. JavaScript doesn’t support that internally, and as you see in my first comment, both "4,3" > 0 and "4,3" < 0 are false, so none of your style classes would ever apply.
What toy said exactly my database returns type varchar so it is mix of letters and numbers. now i have to convert this to numeric how can i convert this whole array. Can i convert this in sql query or what you suggest numeral.js.