Simple Shopping Cart By AngularJS
                                            
 9948 단어  AngularJS
                    
<body ng-controller='CartController'>
    <h1>Your Order</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="~/Scripts/angular.js"></script>
    <script>
        function CartController($scope) {
            $scope.items = [
            { title: 'Paint pots', quantity: 8, price: 3.95 },
            { title: 'Polka dots', quantity: 17, price: 12.95 },
            { title: 'Pebbles', quantity: 5, price: 6.95 }
            ];
            $scope.remove = function (index) {
                $scope.items.splice(index, 1);
            }
        }
    </script>
</body>  Use module:
<body ng-controller='CartController'>
    <h1>Your Order</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="~/Scripts/angular.js"></script>
    <script>
        var myModule = angular.module('myApp', []);
        myModule.controller('CartController', function ($scope) {
            $scope.items = [
            { title: 'Paint pots', quantity: 8, price: 3.95 },
            { title: 'Polka dots', quantity: 17, price: 12.95 },
            { title: 'Pebbles', quantity: 5, price: 6.95 }
            ];
            $scope.remove = function (index) {
                $scope.items.splice(index, 1);
            }
        });
    </script>
</body>
                이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
AngularJS의 ng-options best practise쓸데없는 말은 하지 말고 바로 코드를 찍어라. 리소스를api에 직접 전달하지 말고 문자열이나 정형(예를 들어 귀속된ng-model="selected")을 권장합니다 angular에서 생성된 의value가 무엇인지, ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.