angular js shopping
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title>Title</title> | |
| <script src="../angular-1.5.5/angular.min.js"></script> | |
| <script> | |
| var myapp=angular.module("myapp",[]); | |
| myapp.controller("myCtrl",function($scope){ | |
| $scope.data = { | |
| categories: [{check: false, category: "商品01"}, | |
| {check: false, category: "商品02"}, | |
| {check: false, category: "商品03"}, | |
| {check: false, category: "商品04"}], | |
| //商品明细 | |
| products: [ | |
| {category: "商品01", name: "鼠标", desc: "2016春季爆款", price: "101", imgsrc: "images/TB1_50x50.jpg"}, | |
| {category: "商品01", name: "键盘", desc: "2016夏季爆款", price: "601", imgsrc: "images/TB2_50x50.jpg"}, | |
| {category: "商品01", name: "主机", desc: "2016秋季爆款", price: "3001", imgsrc: "images/TB3_50x50.jpg"}, | |
| {category: "商品01", name: "显示器", desc: "2016冬季爆款", price: "1001", imgsrc: "images/TB3_50x50.jpg"}, | |
| {category: "商品01", name: "鼠标", desc: "2016春季爆款", price: "101", imgsrc: "images/TB1_50x50.jpg"}, | |
| {category: "商品01", name: "键盘", desc: "2016夏季爆款", price: "601", imgsrc: "images/TB2_50x50.jpg"}, | |
| {category: "商品01", name: "主机", desc: "2016秋季爆款", price: "3001", imgsrc: "images/TB3_50x50.jpg"}, | |
| {category: "商品01", name: "显示器", desc: "2016冬季爆款", price: "1001", imgsrc: "images/TB3_50x50.jpg"}, | |
| {category: "商品02", name: "鼠标", desc: "2015春季爆款", price: "101", imgsrc: "images/TB1_50x50.jpg"}, | |
| {category: "商品02", name: "键盘", desc: "2015夏季爆款", price: "601", imgsrc: "images/TB2_50x50.jpg"}, | |
| {category: "商品02", name: "主机", desc: "2015秋季爆款", price: "3001", imgsrc: "images/TB3_50x50.jpg"}, | |
| {category: "商品02", name: "显示器", desc: "2015冬季爆款", price: "1001", imgsrc: "images/TB3_50x50.jpg"}, | |
| {category: "商品03", name: "鼠标", desc: "2014春季爆款", price: "101", imgsrc: "images/TB1_50x50.jpg"}, | |
| {category: "商品03", name: "键盘", desc: "2014夏季爆款", price: "601", imgsrc: "images/TB2_50x50.jpg"}, | |
| {category: "商品03", name: "主机", desc: "2014秋季爆款", price: "3001", imgsrc: "images/TB3_50x50.jpg"}, | |
| {category: "商品03", name: "显示器", desc: "2014冬季爆款", price: "1001", imgsrc: "images/TB3_50x50.jpg"}, | |
| {category: "商品04", name: "鼠标", desc: "2013春季爆款", price: "101", imgsrc: "images/TB1_50x50.jpg"}, | |
| {category: "商品04", name: "键盘", desc: "2013夏季爆款", price: "601", imgsrc: "images/TB2_50x50.jpg"}, | |
| {category: "商品04", name: "主机", desc: "2013秋季爆款", price: "3001", imgsrc: "images/TB3_50x50.jpg"}, | |
| {category: "商品04", name: "显示器", desc: "2013冬季爆款", price: "1001", imgsrc: "images/TB3_50x50.jpg"} | |
| ] | |
| }; | |
| //获取选取的内容 | |
| $scope.fun=function(){ | |
| var n=0; | |
| var j=0; | |
| for(var i=0;i<$scope.data.categories.length;i++){ | |
| if($scope.data.categories[i].check==true){ | |
| n++; | |
| j=i; | |
| } | |
| } | |
| console.log(n); | |
| if(n==0){ | |
| alert("啥都没选"); | |
| }else if(n>=2){ | |
| alert("选多了"); | |
| }else if(n==1){ | |
| alert($scope.data.categories[j].category); | |
| $scope.sel=$scope.data.categories[j].category; | |
| } | |
| }; | |
| //过滤商品 | |
| /* $scope.catFilter=function(item){ | |
| //console.log(item); | |
| if($scope.sel==item.category||$scope.sel==null){ | |
| return true; | |
| }else{ | |
| return false; | |
| } | |
| };*/ | |
| //添加购物车 | |
| $scope.cart=[]; | |
| $scope.add=function(item){ | |
| //console.log(item); | |
| var has=false; | |
| for(var i=0;i<$scope.cart.length;i++){ | |
| if(item.name==$scope.cart[i].item.name){ | |
| console.log(1); | |
| has=true; | |
| $scope.cart[i].num++; | |
| break; | |
| }else{ | |
| console.log(0); | |
| has=false; | |
| } | |
| }; | |
| if(has==false){ | |
| $scope.cart.push({item:item,num:1}); | |
| } | |
| } | |
| }); | |
| </script> | |
| </head> | |
| <body ng-app="myapp" ng-controller="myCtrl"> | |
| <ul> | |
| <li ng-repeat="item in data.categories"> | |
| <input type="checkbox" ng-model="item.check"> | |
| {{item.category}} | |
| </li> | |
| </ul> | |
| <button ng-click="fun()">选取对应商品</button> | |
| <table> | |
| <thead> | |
| <tr> | |
| <td>商品类别</td> | |
| <td>商品名称</td> | |
| <td>商品价格</td> | |
| <td>添加购物车</td> | |
| </tr> | |
| </thead> | |
| <tbody> | |
| <tr ng-repeat="item in data.products|filter:sel"> | |
| <td>{{item.category}}</td> | |
| <td>{{item.name}}</td> | |
| <td>{{item.price}}</td> | |
| <td><button ng-click="add(item)">添加购物</button></td> | |
| </tr> | |
| </tbody> | |
| </table> | |
| <h2>购物车</h2> | |
| <table> | |
| <thead> | |
| <tr> | |
| <th>产品</th> | |
| <th>数量</th> | |
| <th>价格</th> | |
| <th>小计</th> | |
| </tr> | |
| </thead> | |
| <tbody> | |
| <tr ng-repeat="item in cart"> | |
| <td>{{item.item.name}}</td> | |
| <td>{{item.num}}</td> | |
| <td>{{item.item.price}}</td> | |
| <td>{{item.item.price*item.num}}</td> | |
| </tr> | |
| </tbody> | |
| </table> | |
| </body> | |
| </html> |
angular js shopping的更多相关文章
- MVC、MVP、MVVM、Angular.js、Knockout.js、Backbone.js、React.js、Ember.js、Avalon.js、Vue.js 概念摘录
注:文章内容都是摘录性文字,自己阅读的一些笔记,方便日后查看. MVC MVC(Model-View-Controller),M 是指业务模型,V 是指用户界面,C 则是控制器,使用 MVC 的目的是 ...
- angular.js:13920 Error: [$injector:unpr] Unknown provider: $scopeProvider <- $scope <- testServe
angular.js:13920 Error: [$injector:unpr] Unknown provider: $scopeProvider <- $scope <- testSer ...
- (翻译)Angular.js为什么如此火呢?
在本文中让我们来逐步发掘angular为什么如此火: Angular.js 是一个MV*(Model-View-Whatever,不管是MVC或者MVVM,统归MDV(model Drive View ...
- angular.js写法不规范导致错误
以下写法:没有明确指定module和controller,写法不规范. 更改angular.js版本会出bug. <html ng-app> <head> <title& ...
- Angular.js实现折叠按钮的经典指令.
var expanderModule=angular.module('expanderModule',[]) expanderModule.directive('expander',function( ...
- Angular.js通过bootstrap实现经典的表单提交
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <link rel= ...
- python , angular js 学习记录【1】
1.日期格式化 Letter Date or Time Component Presentation Examples G Era designator Text AD y Year Year 199 ...
- Angular JS 学习之路由
1.AngularJS路由允许我们通过不同的URL访问不同的内容:通过AngularJS可以实现多视图的单页WEB访问(SPA) 2.通常我们的URL形式为http://runoob.com/firs ...
- Angular JS 学习之Bootstrap
1.要使用Bootstrap框架,必须在<head>中加入链接: <link rel="stylesheet" href="//maxcdn.boots ...
随机推荐
- Sort HDU5884(二分+多叉哈夫曼树)
HDU5884 Sort 题意:有n个序列要进行归并,每次归并的代价是两个序列的长度的和,要求最终的代价不能超过规定的T,求在此前提下一次能同时进行归并的序列的个数k. 思路:还是太单纯,看完题目一直 ...
- 【微软2017年预科生计划在线编程笔试 A】Legendary Items
[题目链接]:https://hihocoder.com/problemset/problem/1489 [题意] 每轮游戏; 你一开始有p的概率获得超神标记; 如果这轮游戏你没获得超神标记; 那么你 ...
- CentOS 6.5下mysql的安装与配置
一.通过yum自动安装mysql yum install mysql-server my-client 二.初始化及相关配置 安装完mysql数据库以后,会发现会多出一个mysqld的服务,通过输入 ...
- SSM(spring mvc+spring+mybatis)学习路径——2-1、spring MVC入门
目录 2-1 Spring MVC起步 一.回顾Servlet 二.SpringMVC简介 三.搭建SpringMVC第一个案例 四.简单流程及配置 五.使用注解开发Controller 六.参数绑定 ...
- axis实现webservices分布式通信
分布式通信原理 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY2ZsMjAxMjEzMTQ=/font/5a6L5L2T/fontsize/400/fil ...
- libcurl实现解析(3) - libcurl对select的使用
1.前言 在本系列的前一篇文章中.介绍了libcurl对poll()的使用. 參考"libcurl原理解析(2) - libcurl对poll的使用". 本篇文章主要分析curl_ ...
- 1+2+3+...+n不能用while、for、if else等实现
问题描写叙述 求 1+2+ - +n ,要求不能使用乘除法. for . while . if . else . switch . case 等keyword以及条件推断语句. 实际意义不大,题目涉及 ...
- ASP.NET MVC 认证模块报错:“System.Configuration.Provider.ProviderException: 未启用角色管理器功能“
新建MVC4项目的时候 选 Internet 应用程序的话,出来的示例项目就自带了默认的登录认证等功能.如果选空或者基本,就没有. 如果没有,现在又想加进去,怎么办呢? 抄啊.将示例项目的代码原原本本 ...
- oc63--协议@protocol1
// // SportProtocol.h // day17 #import <Foundation/Foundation.h> @protocol SportProtocol <N ...
- android.os.Process.killProcess(android.os.Process.myPid())与Activity生命周期的影响
如果通过finish方法结束了一个Activity,那么根据Activity的生命周期,则会自动调用Activity的销毁方法onDestory(),但是在项目中遇到这样的一个问题,就是Activi ...