初心者のAngularjsは、暇なときに小さなケースを作りました。
機能:ショッピングカートアイテムの価格を計算し、ショッピングカートアイテムを削除します。
以下は完全なケースです(jqueryとangularjsを自分で紹介する必要があります)
<!doctype html> <html ng-app = "myapp"> <head> <meta charset = "utf-8"> <title> un unt titled document </title> <style> .cursors {cursor:pointer} </style> <script src = "js/jquery-1.11.1.js"> </script> < src = "js/angular.min.js"> </script> <script> var a = angular.module( 'myApp'、[]); //ショッピングカートプラスa.directive( 'myAdds'、function(){return {link:function(scope、element、attr){element.click(){var this = thisangular.foreach(scope.datalist、function(data、index、array){if(attr.items == data.items){data.num = parseint(data.num)+1; scope.allprices(); scope a.directive( 'myminus'、function(){return {link:function(scope、element、attr){element.click(function(){var this = thisangular.foreach(scope.datalist、function(data、index、array){if(attr.items == data.items){dat.num <= 1) Product ')){data.num = 0; $(this).siblings(' input ')。val(0); scope.allprices(); scope。$ apply(); // delete array [index]; scope.datalist.splice(index、1)$(this).parents( 'tr')。remove();}} else {data.num = parseint(data.num)-1;}; scope.allprices(); scope。$ apply();}} a.directive( 'allorcan'、function(){return function(scope、element、attr){element.click(function(){var isCheck = $(this).find( 'input')。prop( 'checked'); if(ischeck){$( 'input [type = checkbox]')。prop( 'checked'、true);} xer {input = checkbox] ') ( 'Checked'、false);} angular.foreach(scope.datalist、function(data、index、array){data.bol = ischeck;})scope.allprices(); scope。$ apply();} this = thisangular.foreach(scope.datalist、function(data、index、array){if(attr.items == data.items){var isCheck = $(this).prop( 'checked'); data.bol = ischeck; scope.allprices(); scope。$ apply();}})}) cart {bol: 'false'、name: '洗濯機、num:' 1 '、項目:' 0 '、oneprice:' 900 '、frice:' '}、{bol:' false '、name:' water Heater '、n um:' 1 '、項目:' 1 '、oneprice:'110'、 ''}、{bal: 'fals:' '、'、 '、'、 '、' fals:コンディショナー '、num:' 1 '、items:' 2 '、oneprice:' 116 '、rice:' '}、{bol:' false '、name:' colrigerator '、num:' 1 '、item:' 3 '、' 2087 '、frice:' '}、{bol:' false '、' inductionクッカー '、num:' 1 '、item:' 4 '、oneprice:' 135 '、rice:' '}、{bol:' false '、name:' quilt '、num:' 1 '、item:' 5 '、OnePrice:' 50 '、frice:' '}、{bol:' false '、name:' book '、num:' 1 '、item:' 6 '、oneprice:' 2 '、firs:' '}、{bol:' false '、name:' pen、num: '1'、item: '7'、oneprice: '' 115 '、価格:' '}、{bol:' false '、name:' cup '、num:' 1 '、item:' 8 '、oneprice:' 12 '、price:' '}、{bol:' false '、name:' 1 '、item:' 9 '、oneprice:' 5 '、' '' '' ' }、{bol: 'false'、name: 'snum:' 1 '、items:' 10 '、oneprice:' 13 '、rish:' '}]; //合計価格の計算$ scope.allprices = function(){$ scope.allprice = 0; angular.foreach($ scope.datalist、function(data、index、array){data.price = data.num*data.oneprice; if(data.bol == true){$ scope.allprice+= parseint(data.price;} parseint;} parseint(} parseint);}価格$ scope.cartsort = function(arg){angular.foreach($ scope.datalist、function(data、index、array){arguments.callee ['cartsort('+arg+')'] =!arguments.c allee ['cartsort('+arg+')'] $ scope.datalist = $ filter( 'orderby')($ scope.datalist、arg、arguments.callee ['cartsort('+arg+')'])})})</script> </head> <body ng-controller = "myangular"> <table> <tr> <td> <ラベルAll-orcan> <入力タイプ= "チェックボックス">すべてを選択します/label </label> </td> <td> name </td> <td>数量ng-repeat = "data in datalist"> <td> <input type = "checkbox" one-check iteques = {{data.items}}> </td> <td ng-cloak> {{data.name}}} </td> <td> <入力タイプ= "テキスト" ng-cloak ng-model = "data.num" items = "{{data.items}}"> <button my-adds items = "{{data.items}}" ng-class = "{cursors:true}">+</button> <ボタンmy-minus items = "{{data.items}}}" ng-class = "</td> ng-cloak> {{data.oneprice}} </td> <td ng-cloak> {{data.price}} </td> </tr> </table> <div>合計価格:{{allprices()}} </div> </body> </html> <効果は図に示されています:
労働の結果を尊重します。転載時にソースを示してください(http://blog.csdn.net/sllailcp/article/details/47833315)...