0
$scope.GetDetails={
  Student:[
      {"id":1,"Name":"Apple","Price":3500}
    ],
  Student:[
      {"id":2,"Name":"Samsung","Price":4000}
     ],
  Student:[
    {"id":3,"Name":"Nokia","Price":1500},
    {"id":3,"Name":"Nokia","Price";7000}
   ]
 }

Am binding data using ng-repeat

 <div ng-repeat="As in GetDetails">
         <div ng-repeat="A in As.Student">
        <span>{{A.Name}}</span> - <span>{{A.Price}}</span>  
    </div>
     </div>

Result is Apple - 3500 Samsung - 4000 Nokia - 1500 Nokia - 7000

Here every thing Ok.But what i want mean , Nokia have two array ,so i have to get name from first array and price from 2nd array Like,

Nokia - 7000,

And Also i need the length of student array.

1
  • 1
    you have to change the json format, the code you have given will not work with your HTML Commented Jun 6, 2017 at 9:37

2 Answers 2

1

First, You should change your JSON to achieve your result.

Change JSON to below:

$scope.GetDetails=[
    {Student:[{"id":1,"Name":"Apple","Price":3500}]},
    {Student:[{"id":2,"Name":"Samsung","Price":4000}]},
    {Student:[{"id":3,"Name":"Nokia","Price":1500},{"id":3,"Name":"Nokia","Price":7000}]}
 ]

Please run below code

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<body>

<div ng-app="myApp" ng-controller="myCtrl">

 <div ng-repeat="As in GetDetails">
         <div ng-repeat="A in As.Student" ng-if="$last">
        <span>{{A.Name}}</span> - <span>{{A.Price}}</span>  
    </div>
     </div>
</div>

<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
    $scope.GetDetails=[
    {Student:[{"id":1,"Name":"Apple","Price":3500}]},
    {Student:[{"id":2,"Name":"Samsung","Price":4000}]},
    {Student:[{"id":3,"Name":"Nokia","Price":1500},{"id":3,"Name":"Nokia","Price":7000}]}
 ]

});
</script>

</body>
</html>

I used ng-if="$last" to take the last value from array

Here is a working DEMO

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

9 Comments

@Vediyappan.V, checked it?
Thanks for Reply its working well..I have one more doubt , How can find length of array. Ex student - Apple - Length 1,student - Samsung- Length 1,student - Nokia- Length 2. Just i need t bind length on ng-repeat.
@Vediyappan.V, you can use {{GetDetails.length}}, check the plnkr.co/edit/LSg6fkOK4exuoT2FDdQq?p=preview
@Vediyappan.V, anything else needed in this answer?
Thanks agian.J have one more doubt . While using JQuery library it cannot support all the function. EX. <script src="ajax.googleapis.com/ajax/libs/jquery/3.2.1/…> Its for calender control and <script type="text/javascript" src="code.jquery.com/jquery-1.7.1.min.js"></script> this other .I Want use both . Have any solution for this.
|
0

If you want this only for Name: Nokia, then do it like;

<div ng-repeat="A in As.Student">
 <span ng-if="A.Name!=='Nokia'">{{A.Name}}-{{A.Price}}</span>  
 <span ng-if="A.Name==='Nokia' && $last">{{A.Name}}-{{A.Price}}</span>  
</div>

and it you want only last element from every array :

then:

 <div ng-repeat="A in As.Student" ng-if="$last">
        <span>{{A.Name}}</span> - <span>{{A.Price}}</span>  
 </div>

Comments

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.