0
HTML如何發佈從ng-repeat獲取的列表到angularjs中的api?
<body class="res layout-subpage" ng-app="cartApp" ng-controller="cartController">
<table class="table table-bordered">
<thead>
<tr>
<td class="text-center">Image</td>
<td class="text-left">Product Name</td>
<td class="text-left">Product Id</td>
<td class="text-left">Quantity</td>
<td class="text-right">Unit Price in (₹)</td>
<td class="text-right">Total </td>
</tr>
</thead>
<tbody id="cartItems">
<tr ng-repeat="product in productsInCart">
<td class="text-center">
<a href="product.html"><img width="70px" src="{{product.ProductImage}}" alt="{{product.ProductName}}" title="Xitefun Causal Wear Fancy Shoes" class="img-thumbnail" />
</a>
</td>
<td class="text-left"><a href="product.html">{{product.ProductName}}</a>
</td>
<td class="text-left" ng-model="product.price">{{product.pid}}</td>
<td class="text-left" width="200px">
<div class="input-group btn-block quantity">
<input type="text" name="quantity" value="{{product.qty}}" ng-model="product.qty" ng-text-change="UpdateItemPrice(product)" size="1" class="form-control" />
<span class="input-group-btn">
<button type="submit" data-toggle="tooltip" title="Update" class="btn btn-primary"><i class="fa fa-clone"></i></button>
<button type="button" data-toggle="tooltip" title="Remove" class="btn btn-danger" ng-click="removeProductFromCart(product.pid)" onClick=""><i class="fa fa-times-circle"></i></button>
</span>
</div>
</td>
<td class="text-right" ng-model="products.price">{{product.price}}</td>
<td class="text-right" ng-model="product.itemTotal">{{product.price * product.qty}}
<input type="hidden" ng-model="product.itemTotal" value="{{product.price * product.qty}}" />
</td>
</tr>
</tbody>
</table>
</body>
角控制器
var cartApp = angular.module('cartApp', []);
cartApp.controller("cartController", ['$scope', function($scope, $http) {
$scope.PostCartDataforOffers = function() {
var listInput = element(by.model('product'));
$scope.productsInCart = [];
angular.forEach($scope, function(value, index) {
$scope.productsInCart.push({
shoppedetail: {
pid: value.pid,
price: value.price,
qty: value.qty,
tp: value.total
}
});
});
$scope.productsInCart.push({
shoppedetail: {
pid: products.pid,
price: products.price,
qty: products.qty,
tp: products.total
}
});
//$scope.productsInCart.push(products);
$http({
url: '/Cart/Details',
method: 'Post',
data: $scope.productsInCart,
}).success(function(data) {
console.log(data)
}).error(function(data) {
console.log(data)
})
}
}]);
現在我要發佈這些行作爲MVC模式的列表。 成功從Object中檢索並顯示在表格行中的數據,但我想要將此多行作爲MVC模型的控制器列表發佈。基本上這是我需要在服務器上發佈的購物車項目。
您使用的服務器端堆棧是? – garfbradaz
我正在使用localstorage在HTML中呈現此數據。 var cartValue = localStorage.getItem(「cartItems」); cartValue ='['+ cartValue +']'; console.log(cartValue); var cartObj = JSON.parse(cartValue); $ scope.productsInCart = cartObj; –