ChaseLouisPowers
ChaseLouisPowers

Reputation: 755

Using Number Filter in AngularJS ng-style

What is the preferred way of using a number filter in ng-style? I have an image that I want to only be set to a whole number pixel value of height.

<img src="ok-button.png" ng-style="{'height': textHeight * 1.888 | number:0}">

The above code does not work but reflects what I'm trying to do.

Upvotes: 1

Views: 481

Answers (1)

Pankaj Parkar
Pankaj Parkar

Reputation: 136134

Height property should have mentioned in pixel so you need to add px to indicate it is pixel.

You were using number filter which is used to change text to , separated currency representation, which would applicable to solve your case.

For rounding pixels you should have define function inside controller which will do Math.roud of that value & return it to the view.

HTML

ng-style="{'height': round(textHeight) + 'px'}"

Code

$scope.round = function(textHeight){
  var result = textHeight * 1.88;
  return Math.roud(result);
}

Upvotes: 1

Related Questions