How to realize Shopping cart by AngularJs
This article is about how AngularJs implements a shopping cart. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Code:
Shopping cart .box {width: 100%; border-bottom: 1px solid silver;} .box1 {width: 100%; margin-top: 5px;} .box1 button {width: 100px; height: 40px; background: crimson; color: white; text-align: center; line-height: 40px; float: right; border: 0; border-radius: 13px } table {width: 100%;} tr td button {background: blue; color: white; border: 0;} var my=angular.module ("my", []) My.controller ("mys", function ($scope) {/ * declare data objects and initialize commodity information Data self-designed and not less than four * / $scope.arr= [{name: "qq", price:12.9,number:2,state:false}, {name: "wx", price:23.9,number:1,state:false}, {name: "aa", price:99.9,number:1,state:false}, {name: "bb", price:10.9,number:5,state:false}] / * delete entry * / $scope.del=function (index) {if (confirm ("are you sure you want to remove this item?")) {$scope.arr.splice (index,1);}} / * Click the "+" button to add 1 to the quantity in the input box, and you can calculate the subtotal price of the goods and the total price of the shopping car * / $scope.jia=function (index) {$scope.arr [index] .number + +. } / * when the "-" button is clicked, the quantity in the input box is minus 1, and the total price of the commodity is * / $scope.jian=function (index) {if ($scope.arr [index] .number > 1) {$scope.arr [index] .number-- } else if ($scope.arr [index] .number = = 1) {if (confirm ("whether the user deletes the product") {$scope.arr.splice (index,1);} / * calculate the total price * / $scope.allSum=function () {var allPrice=0; for (var itemo / I)