0

I am working on an Angular project. I have this table, which I build but I don't know in advance how big the font should be. Because of that i created this function (this is the code i have inside of it):

$('.td').css({
    'font-size': Number(this.f) + 'px'
});

//Mobile
  $('.mobileTdLong').css({
      'width': Number(this.f) + 150 + 'px'
  });

  $('.mobileTdShort').css({
    'width': Number(this.f) + 40 + 'px'
  });

//Desktop
  $('.tableDesktopShort').css({
    'width': Number(this.f) + 100 + 'px'
  });

NOTE: f is a variable from user input.

The code I have written isn't the best one for my problem because it doesn't permenantly change my table font.. It just flickers (from 20px which is set by default in .css file, to this.f value). The reason I need this is because every 10 seconds the table values are refreshed.

I hope I provided enough information. Thanks

3 Answers 3

2

You should get rid of everything that is jquery related. It does not belong in an Angular solution And then you should handle the styling with CSS media queries

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

4 Comments

Thanks i looked into it. However i didn't find how this should be set up. Could you give an example?
ok i think i found that this does the trick : [style.font-size.px]="f"
seriously, you should spend some time on understanding Angular better, and get rid of all jquery. Also take it out of your package.json. I can recommend Angular course on udemy, by Maximllian.
i agree, thats why i asked this question :) and i am already following Maximilian on Udemy thanks.
1

AngularJS 1.7 or Angular 6.0? instead of a jquery lite selector, you can try inline styles :

<table [ngStyle]="getStylesTableOnMobileView()">
 ...
</table>

you can also do same with ngClass.

Comments

0

You shouldn't use jQuery in Angular. If you need to dinamically change classes of html elements I recommend you to use [(ngClass)] or media queries.

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.