标签:
之前用jQuery实现一个购物车,里面设计到很多DOM操作,对于这个DOM free的框架,实现购物车功能还是很省代码的。
<html ng-app=‘myApp‘> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>购物车</title> </head> <body ng-controller=‘CartController‘> <h1>您的订单</h1> <div ng-repeat=‘item in items‘> <span>{{item.title}}</span> <input ng-model=‘item.quantity‘> <span>{{item.price | currency}}</span> <span>{{item.price * item.quantity | currency}}</span> <button ng-click="remove($index)">Remove</button> </div> <script src="http://cdn.bootcss.com/angular.js/1.5.0-beta.1/angular.js"></script> <script> var myApp=angular.module(‘myApp‘,[]) myApp.controller(‘CartController‘, function($scope) { $scope.items = [{title:‘西瓜‘,quantity:8,price:3.95},{title:‘西红柿‘,quantity:17,price:12.95},{title:‘苹果‘,quantity:5,price:6.95}]; $scope.remove = function(index) { $scope.items.splice(index,1); } }); </script> </body> </html>
标签:
原文地址:http://www.cnblogs.com/JAYIT/p/4977906.html