Home > Web Front-end > JS Tutorial > body text

AngularJS implements price calculation function

php中世界最好的语言
Release: 2018-04-13 14:21:24
Original
1500 people have browsed it

This time I will bring you AngularJS to implement the price calculation function. What are the precautions for AngularJS to implement the price calculation function? The following is a practical case. Let’s take a look. .

The code is as follows:

<!DOCTYPE html>
<html lang="en" ng-app>
<head>
 <meta charset="UTF-8">
 <title>www.jb51.net angular计算总价</title>
 <link rel="stylesheet" type="text/css" href="style.css" rel="external nofollow" >
 <script type="text/javascript" src="../libs/angular.min.js"></script>
</head>
<body>
 <table>
  <tr><td>单价:</td><td><input type="text" ng-model="price"></td></tr>
  <tr><td>数量:</td><td><input type="text" ng-model="number"></td></tr>
  <tr><td>总价:</td><td>{{price*number|currency:'¥'}}</td></tr>
 </table>
</body>
</html>
Copy after login

There are a few points to note:

<script type="text/javascript" src="../libs/angular.min.js"></script> Introduction to angularjs Script;
<html lang="en" ng-app>                                                                                                                                        model="price"> The data comes from the input with ng-model="price"
/ng-model="number" attribute Box;{{price*number|currency:'¥'}} After obtaining the data from the input, perform the operation in {{ }} and display the result in td middle. Among them, | currency:'¥'
is filter, which can format numbers into currency. If not specified, the default is $. I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website! Recommended reading:

vue-cli How to configure lib-flexible rem mobile terminal adaptation

vue-cli Detailed explanation of usage

The above is the detailed content of AngularJS implements price calculation function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template