前端开发AngularJS中的$index

网易游戏前端开发
前端开发游戏卡顿原因
游戏开发是wed前端开发吗

代码片段 1

<html ng-app>
    <head>
        <meta charset=”utf-8″ />
        <title>购物车</title>
        <link
            href=”http://cdn.bootcss.com/bootstrap/3.3.1/css/bootstrap.min.css
            rel=”stylesheet”
        />
    </head>
    <body ng-controller=”CartController”>
        <h1>Your Order</h1>
        <div ng-repeat=”item in items”>
            <div class=”form-group col-sm-5″>
                <label>{{ item.title }}</label>
                <input
                    type=”text”
                    ng-model=”item.quantity”
                    class=”form-control”
                />
            </div>
            <div class=”form-group col-sm-7″>
                <div class=”from-group col-sm-2″>
                    <label>price</label>
                    <p class=”form-control” style=”border:0;box-shadow:none”>
                        {{ item.price | currency }}
                    </p>
                </div>
                <div class=”form-group col-sm-2″>
                    <label>Summary</label>
                    <p class=”form-control” style=”border:0;box-shadow:none”>
                        {{ item.price * item.quantity | currency }}
                    </p>
                </div>
                <button
                    ng-click=”remove($index)”
                    class=”btn btn-default col-sm-2″
                    style=”margin-top:23px”
                >
                    Remove{{ $index }}
                </button>
            </div>
            <div class=”clearfix”></div>
        </div>
        <script src=”http://cdn.bootcss.com/angular.js/1.3.0-beta.13/angular.min.js”></script>
        <script>
            function CartController($scope) {
                $scope.items = [
                    { title: ‘Paint pots’, quantity: 8, price: 3.95 },
                    { title: ‘Paint pots2’, quantity: 9, price: 4.95 },
                    { title: ‘Paint pots3’, quantity: 10, price: 5.95 },
                ]
                $scope.remove = function(index) {
                    $scope.items.splice(index, 1)
                }
            }
        </script>
    </body>
</html>

这是《使用angularjs开发下一代web应用》中的代码,书中没有对$index作出解释,我就自己去查找了下。
$index只在ng-repeat中起作用,它的作用是获取当前标签的索引值。除了$index外还有$first,$middle,$last,$even,$odd。
具体参考:http://www.ngnice.com/docs/api/ng/directive/ngRepeat

游戏开发是属于前端吗
前端棋牌游戏开发代码
前端能开发游戏?
赞(0)
前端开发者 » 前端开发AngularJS中的$index
64K

评论 抢沙发

评论前必须登录!