0

I'm making my first Angular app and am struggling with the thought processes behind conditionally styling the DOM in AngularJS.

I was previously doing this in jQuery like so:

containerWidth = lineWidth / numberOfObjects; $container.css('width',containerWidth);

So if there's 1 object the width is 100% and if there are 5 the width becomes 20%.

I'm unsure whether to do this in link, inside a directive or in the controller itself?

Mark McDermid
  • 109
  • 1
  • 11
  • DOM manipulation is basically done in Directive, However, you can use jquery syntax inside controler. eg .$("your selector").css() in controler – Vishu238 Aug 27 '15 at 10:29
  • Possible duplicate: http://stackoverflow.com/questions/20287241/how-to-set-div-width-using-ng-style –  Aug 27 '15 at 10:31

1 Answers1

2

Please see ng-style

Example:

<div ng-style="divStyle" />

and JS:

$scope.divStyle = {'width' : (lineWidth / numberOfObjects) + 'px;' };

(I don't know where lineWidth comes from... but that's the idea)