0

I create two global variables such as var DiscountRef = {};var shareDetail = []; when the user add the form I store all the values in DiscountRef variable such as

RefValue = {Mobile:9876543210,Quantity:3}
$scope.shareDetail = Object.Keys(RefValue);//I try Object.entries also

when I want to display the data in the table

{{shareDetail}}
<div ng-repeat="share in shareDetail">
  {{share.Mobile}}
  {{share.Quantity}}
 
</div>

Its displaying empty array

I also try this

 <div ng-repeat="(key, value) in shareDetail">
    {{key}} : {{value}}
 </div>

It will get the result.how can I access particular key value pairs such as MobileNo:9876543210 & Quantity:3

1
  • try this: $scope.shareDetail = [RefValue ]; Commented Jul 20, 2020 at 15:02

1 Answer 1

1
$scope.value = {Mobile:9876543210,Quantity:3};
$scope.shareDetail = [];
Object.keys($scope.value).forEach(function(key, value)
{
    $scope.shareDetail.push({"item_name": key, "value": $scope.value[key]});
});

Then you can do ng-repeat:

<div ng-repeat="(key, item) in shareDetail">      
    {{item.item_name}} : {{item.value}}
</div>

Thanks

Sign up to request clarification or add additional context in comments.

4 Comments

I already get the result in the above code but I want Mobile,Quantity value to be used in the a tag such as <a href="{{Mobile.value}}">
as you have Mobile & Quantity value so what's problem are you facing?
@Michael I have updated my code, could you please try now and let me know. Thanks
welcome. @Michael please accept the answer if it works :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.