0

This is my angularjs function

$scope.getSpecificCat = function(p_cat) {
    $http.get(url+'getSpecificCatJson/' + p_cat).success(function(data){         
    $scope.specifics = data;         
  }).error(function(){
    //alert('there is some errror while fetching product ');
  });   
}

The specifics contain two arrays like [Array[2],Array[2]]. Now my question is that how show these arrays values in ng-repeat.I want to elaborate my question that first array contain data like 0:object while object have product_name:"tv" while second array have 0:"30" This is my modal public function get_specific_cat($p_cat)

{                 
                 $current_date = date('d-M-Y');
                 $current_new  = strtotime($current_date);
                 $this->db->select("*, ((p_bid/total_bid)*100) as progress");
                // print_r($current_new);die;
                 $this->db->where('p_cat',$p_cat); 
                 $this->db->where('p_status','active');
        $query = $this->db->get('product');
        $data  = $query->result();
         $percent_array =[];

          foreach ($data as $row) {
            $id  = $row->p_id;
            $ppr = $row->pp_date;
            $pcr = $row->pc_date;
            $ppn = strtotime($ppr);
            $pcn = strtotime($pcr);
            $p_name = $row->p_name;
             if($row->p_cat == 'diamond')
             {
              return $data;
             }
             else if($row->p_cat == 'gold' && $ppr < 1)
            {
               return $data ;
            }
            else if(!empty($pcn && $ppn) && $pcn != $ppn)
            {
            $percent_array[] = (($current_new-$ppn) * 100)/($pcn-$ppn);
          //  $percent_data = array('0' => $percent_array , );

          } 


          }

             $percent_data = array('0' =>$data, '1' => $percent_array);
             return $percent_data; 


}

i wand percentage as well as data for ng-repeat

2 Answers 2

2

So your data looks like something like this:

$scope.items = [
    ['Val1', 'Val2'],
    ['Val1', 'Val2']
];

You can loop over with 2 ng-repeat, as follow:

<div ng-repeat="i in items">
    <div ng-repeat="j in i">{{j}}</div>
</div>

Demo on JSFiddle

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

4 Comments

in this case one array contains integer array while the second array contains object
plz give a kind look to the asked question again
Provide your JSON object in your question, I don't understand what its structure is.
i added the modal return data
0

If you want to iterate over all the items in all the arrays within the main array:

$scope.specifics = data;
$scope.specificsFlat = (data || []).reduce(function(mainArray, array) { 
  return mainArray.concat(array);
}, []);

Then you can use specificsFlat

<div ng-repeat="specific in specificsFlat">
  {{ specific.whatever }}
</div>

This will flatten your main array by taking the values from the sub-arrays and placing them all on the same level.

2 Comments

but i am unable to get second array values because i do not know their index
i have modified my question look again

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.