2017-03-04 7 views
0

Ich bin neu in eckig, ich versuche, einen einfachen Warenkorb zu entwickeln, ich habe gerade eine Liste von Produkten erstellt, aber ich bekomme nicht, wie ich sie in den Warenkorb legen würde?Ich versuche einen einfachen Warenkorb zu erstellen, aber ich habe versucht Produkte in den Warenkorb zu legen.

hier ist mein Plunker Link: https://plnkr.co/edit/oo05d6H6AxuJGXBAUQvr?p=preview

kann man auch sagen, wie kann ich meinen Code effizienter für Benutzer machen?

würde jede Art von Hilfe hoch

<!DOCTYPE html> 
<html> 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> 
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-route.js"></script> 
<script src="script.js"></script> 
<body ng-app="myApp" ng-controller="mobileController"> 
<h2> Welcome to Mobile Store</h2> 

<p>Search:<input type="text" ng-model="test"></p> 


<ul> 
<li ng-repeat="item in items|filter:test"><a href="#/item/{{item.name}}">{{ item.name }}</a> 
    </li> 

</ul> 



<div ng-view></div> 

    </body> 

</html> 
// Code goes here 



var app = angular.module("myApp", ["ngRoute"]); 
app.controller('mobileController', function($scope) { 
    $scope.items = [{ 
    name: 'Iphone', 
    price: 70000, 
    rating: '*****', 
    image: 'http://i.imgur.com/hfMaGTN.png' 
    }, { 
    name: 'Oneplus', 
    price: 60000, 
    rating: '****', 
    image: 'http://i.imgur.com/sBcs5ZE.jpg' 
    }, { 
    name: 'Samsung', 
    price: 50000, 
    rating: '***', 
    image: 'http://i.imgur.com/8Bexxbf.jpg' 
    }, { 
    name: 'Sony', 
    price: 40000, 
    rating: '***', 
    image: 'http://i.imgur.com/0c7PcX8.png' 
    }, { 
    name: 'Moto', 
    price: 20000, 
    rating: '****', 
    image: 'http://i.imgur.com/HyWR1VE.png' 
    }]; 
}); 
app.config(function($routeProvider) { 
    $routeProvider 
    .when('/item/:itemName', { 
     templateUrl: 'details.html', 
     controller: 'ItemCtrl' 
    }); 
}); 

app.controller('ItemCtrl', ['$scope', '$routeParams', 
    function($scope, $routeParams) { 
    angular.forEach($scope.items, function(item) { 
     if (item.name == $routeParams.itemName) { 
     $scope.itemName = item.name; 
     $scope.itemPrice = item.price; 
     $scope.itemRating = item.rating; 
     $scope.itemImage = item.image; 
     } 
    }); 
    } 
]); 

This is the details page 
<!DOCTYPE html> 

<p>ItemName: {{itemName}}</p> 
<p> ItemPrice: {{itemPrice}}</p> 
<p>ItemRating:{{itemRating}}</p> 
<img src="{{itemImage}}"> 
<p><input type = "submit" value = "Add to Cart" ng-click = "addProduct()"></p> 

sollte ich addProduct Funktion in der gleichen ItemCtrl (Controller) umfassen geschätzt werden?

+0

wo Sie Schreib addProduct() Code ?? – Darshak

Antwort

Verwandte Themen