Select all and invert z during checkout in AngularJS shopping cart
This time I bring to you, what are the precautions, the following is a practical case, let's take a look.
Without further ado, I will just post the code for you. The specific code is as follows;
nbsp;html> <meta> <title></title> <link> <style> .p1{ margin: 20px; } </style> <p> </p><h4 id="angularJS-购物车实现全选-取消全选">angularJS--购物车实现全选/取消全选</h4> <button>添加商品</button> <button>删除商品</button> <br><br>
操作 | check状态 | 商品名称 | 单价 | 数量 | 小计 |
{{p.checked}}||{{p.checked}} | {{p.name}} | 单价:¥{{p.price}} | 数量: | 小计:¥{{p.sum}} |
全选取消全选
已选择{{jishuqi}}件商品,总金额:¥{{ sumTotal }} <script></script> <script> angular.module('testMo',['ng']).controller('testCtrl',function($scope){ // $scope.p1=new Object(); // $scope.p1.price=10; // $scope.p1.count=1; //购物车应该是一个数组 $scope.selectAll=false;//全选默认为false $scope.cart=[{id:0,name:'商品0',price:10,count:5,sum:10,checked:false}]; $scope.addProduct= function (){ var p=new Object(); p.id=$scope.cart.length; p.name='商品'+ p.id p.price=Math.floor(Math.random()*100);//对数值向下取整 p.count=1; p.sum= p.price* p.count; p.checked=false; $scope.cart.push({id: p.id,name: p.name,price:p.price,count: p.count,sum: p.sum,checked: p.checked}); console.log($scope.cart); } //删除商品 $scope.deleteProduct= function (){ $scope.cart.pop();//删除数组中的最后的一个元素,并且返回这个元素,会改变数组里的元素 } //全选按钮check的点击事件 $scope.selectAllClick= function (sa) { for(var i=0;i<$scope.cart.length;i++){ $scope.cart[i].checked=sa; } } //单个数据的check事件 $scope.echoChange=function(id,ch,se){ $scope.cart[id].checked=!ch; //当所有都选中时,全选也要被勾选 var cc=0;//计算当前数组中checked为真的数目 for(var i=0;i<$scope.cart.length;i++){ // if($scope.cart[i].checked==true){ // cc++; // } $scope.cart[i].checked?cc++:cc; } $scope.selectAll=(cc==$scope.cart.length);//当为真的数目=数组长度时,证明全部勾选 // console.log($scope.selectAll); } //监控数据 $scope.$watch('cart',function(newValue,oldValue,scope){ $scope.sumTotal=0; //总计 $scope.jishuqi=0; //计数器 for(var i in newValue) { var sumN = newValue[i].count * newValue[i].price; //计算出新的结果 $scope.cart[i].sum = sumN.toFixed(2); //保留两位小数并且把它赋值给元数据; if (newValue[i].checked) { $scope.sumTotal += sumN; $scope.jishuqi++; // console.log($scope.sumTotal); // console.log($scope.jishuqi); } } },true); /*$watch简介:在digest执行时,如果watch观察的的value与上一次执行时不一样时,就会被触发。 AngularJS内部的watch实现了页面随model的及时更新。 $watch方法在用的时候主要是手动的监听一个对象,但对象发生变化时触发某个事件。 $watch(watchFn,watchAction,deepWatch); 如果不加第三个参数,那么只会监听cart数组,只有当cart引用改变时才会触发,因此当需要监听一些引用对象时需要把第三个参数设置成true。 */ }); </script>
PS: Let me share with you the code of the angularjs shopping cart. The specific code is as follows:
nbsp;html> <meta> <title>购物车</title> <script></script> <center> <h2 id="商品列表">商品列表</h2> <p> <!--导航栏--> <nav> <p> </p> <p> </p> <p> <input> 产品价格: <select> <option>0-1000</option> <option>1000-2000</option> <option>2000-5000</option> </select> <input> </p> </nav></p> <br> <table> <thead> <tr> <th> 产品编号 <span></span> </th> <th> 产品名称 <span></span> </th> <th> 产品价格 <span></span> </th> <th> 操作 <span></span> </th> </tr> </thead> <tbody> <tr> <td> {{item.id}} </td> <td> {{item.name}} </td> <td> {{item.price | currency:'(RMB)'}} </td> <td> <input> </td> </tr> </tbody> </table> <script> angular.module('product',[]) .factory('productList',function(){ return [ { id:910,name:"imac",price:15400 }, { id:80,name:"iphone",price:5400 }, { id:29,name:"ipad",price:14200 }, { id:500,name:"ipad air",price:23400 }, { id:1200,name:"ipad mini",price:22000}, { id:100,name:"android",price:9990 } ] }) .controller('productController',function($scope,productList){ /*$scope.search = "ipad";//定义一个变量 alert($scope.search);*/ $scope.productList=productList $scope.orderColumn='name'; //排序字段 $scope.orderSign='-'; //为空时正序 为负号时倒序 $scope.sortProduct=function(sortColumn){ //点击列标题排序事件 $scope.orderColumn=sortColumn;//觉得按照那一列进行排序 if($scope.orderSign=="-"){ $scope.orderSign=""; }else{ $scope.orderSign='-'; } }; //删除产品 $scope.delProduct = function(name){ //alert(name); if(name!=""){ if(confirm("是否删除"+name+"商品") ){ var p; for (index in $scope.productList) { p = $scope.productList[index]; if(p.name == name){ $scope.productList.splice(index,1); } } } } } //清空购物车 $scope.removeAll = function(){ if(confirm("你确定要清空购物车所有商品吗?")){ $scope.productList = []; } } }); </script> </center>
Okay, this ends the code.
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:
The above is the detailed content of Select all and invert z during checkout in AngularJS shopping cart. For more information, please follow other related articles on the PHP Chinese website!

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.

The power of the JavaScript framework lies in simplifying development, improving user experience and application performance. When choosing a framework, consider: 1. Project size and complexity, 2. Team experience, 3. Ecosystem and community support.

Introduction I know you may find it strange, what exactly does JavaScript, C and browser have to do? They seem to be unrelated, but in fact, they play a very important role in modern web development. Today we will discuss the close connection between these three. Through this article, you will learn how JavaScript runs in the browser, the role of C in the browser engine, and how they work together to drive rendering and interaction of web pages. We all know the relationship between JavaScript and browser. JavaScript is the core language of front-end development. It runs directly in the browser, making web pages vivid and interesting. Have you ever wondered why JavaScr

Node.js excels at efficient I/O, largely thanks to streams. Streams process data incrementally, avoiding memory overload—ideal for large files, network tasks, and real-time applications. Combining streams with TypeScript's type safety creates a powe

The differences in performance and efficiency between Python and JavaScript are mainly reflected in: 1) As an interpreted language, Python runs slowly but has high development efficiency and is suitable for rapid prototype development; 2) JavaScript is limited to single thread in the browser, but multi-threading and asynchronous I/O can be used to improve performance in Node.js, and both have advantages in actual projects.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Mac version
God-level code editing software (SublimeText3)

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.
