如何使用angularjs在ng-repeat中使用自定义范围变量 [英] How to use custom scope variable within ng-repeat using angularjs

查看:71
本文介绍了如何使用angularjs在ng-repeat中使用自定义范围变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们必须使用angularjs在ng-repeat中使用自定义范围varibale,但它会将最后一个值返回给所有



我尝试过:



We have to use custom scope varibale within ng-repeat using angularjs, but it will return last value to all

What I have tried:

<div ng-repeat="pro in UserProduct">
{{discountvalue}}
</div>

<script>
 $http.get('/api/Product/ListOnlyProductOrderFeatured/', { params: {} }).success(function (data) {
$scope.UserProduct = data;
for (var i = 0; i < $scope.UserProduct.length; i++) {
$scope.generalprice = $scope.UserProduct[i].ec_shop_product_price;
$scope.discountprice = $scope.UserProduct[i].ec_shop_product_discount;

$scope.discountvalue = $scope.generalprice - $scope.discountprice;

}
})
</script>

推荐答案

http.get('/ api / Product / ListOnlyProductOrderFeatured /',{params:{}})。 success(function(data){
http.get('/api/Product/ListOnlyProductOrderFeatured/', { params: {} }).success(function (data) {


scope.UserProduct = data;
for(var i = 0; i<
scope.UserProduct = data; for (var i = 0; i <


scope .UserProduct.length; i ++){
scope.UserProduct.length; i++) {


这篇关于如何使用angularjs在ng-repeat中使用自定义范围变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆