Android之父_实现购物车系列

第一步:导入包文件并且声明
  var app = angular.module("myApp", ['ngRoute']);  
第二步//配置路由
app.config(["$routeProvider", function($routeProvider) {
                $routeProvider
                    .when('/', {
                        templateUrl: '',
                    })
                    .when("/news", {
                        templateUrl: 'news.html',
                        controller: 'newsController'

                    })
                    .when("/news", {
                        templateUrl: 'news.html',
                        controller: 'newsController'

                    })
                    .when("/query", {
                        templateUrl: 'query.html',
                        controller: 'queryController'

                    })
                    .when("/day", {
                        templateUrl: 'day.html',
                        controller: 'dayController'

                    })
                    .when("/team", {
                        templateUrl: 'team.html',
                        controller: 'teamController'

                    })
            }]);
第三步:实现新闻页面的控制器
app.controller("newsController", function($scope) {
                //模拟数据源
                $scope.shopList = [{
                    id: 1,
                    title: "纯手工制作木质时钟精致家具装饰摆件",
                    price: 150,
                    num: 1,
                    state: false
                }, {
                    id: 2,
                    title: "木质蓝牙音箱包邮实木家具装饰摆件",
                    price: 119,
                    num: 1,
                    state: false
                }, {
                    id: 3,
                    title: "装饰木雕,独特趣味设计家具装饰摆件",
                    price: 120,
                    num: 1,
                    state: false
                }];
//删除全部,批量删除
                $scope.removeAll = function() {
                    var userNames = [];
                    for(index in $scope.shopList) {
                        if($scope.shopList[index].state == true) {
                            userNames.push($scope.shopList[index].title);
                        }
                    }
                    alert(userNames);
                    if(userNames.length > 0) {
                        if(confirm("是否删除选中项?")) {
                            for(i in userNames) {
                                var name = userNames[i]
                                for(i2 in $scope.shopList) {
                                    if($scope.shopList[i2].title == name) {
                                        $scope.shopList.splice(i2, 1);
                                    }
                                }
                            }
                        }
                    } else {
                        alert("请选择删除项");
                    }
                }

//全选
                $scope.selectAll = false;
                $scope.all = function(m) {
                    for(var i = 0; i < $scope.shopList.length; i++) {
                        if(m === true) {
                            $scope.shopList[i].state = true;
                        } else {
                            $scope.shopList[i].state = false;
                        }
                    }
                }
            });
//body中的内容

        

你可能感兴趣的:(Android之父_实现购物车系列)