1

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.

1 Answer 1

1

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);
}
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.