Math functions in AngularJS bindings

后端 未结 13 1176
无人及你
无人及你 2020-11-29 17:55

Is there a way to use math functions in AngularJS bindings?

e.g.

The percentage is {{Math.round(100*count/total)}}%

13条回答
  •  天命终不由人
    2020-11-29 18:24

    The easiest way to do simple math with Angular is directly in the HTML markup for individual bindings as needed, assuming you don't need to do mass calculations on your page. Here's an example:

    {{(data.input/data.input2)| number}} 
    

    In this case you just do the math in the () and then use a filter | to get a number answer. Here's more info on formatting Angular numbers as text:

    https://docs.angularjs.org/api/ng/filter

提交回复
热议问题