Angularjs Loop the record based on array - angularjs

I am using Angular js
after hit I got response below response how to loop it
one div name then value like this i want to loop
my response
{
"my2":[
{
"id":5,
"cuid":20,
"name":"my2",
"month":"04",
"created_at":"2018-04-01 00:00:00",
"updated_at":"2018-04-11 00:00:00",
"time":"04:32 PM",
"status":"D"
},
{
"id":4,
"cuid":20,
"name":"my2",
"month":"04",
"created_at":"2018-04-02 00:00:00",
"updated_at":"2018-04-12 00:00:00",
"time":"12:10 PM",
"status":"P"
},
],
"my":[
{
"id":44,
"cuid":21,
"name":"my",
"month":"04",
"created_at":"2018-04-12 00:00:00",
"updated_at":"2018-04-12 00:00:00",
"time":"09:08 PM",
"status":"P"
}
],
"Testing":[
{
"id":43,
"cuid":19,
"name":"Testing",
"month":"04",
"created_at":"2018-04-12 00:00:00",
"updated_at":"2018-04-12 00:00:00",
"time":"09:05 PM",
"status":"P"
}
]
}
i try this
<div ng-repeat="data in reports" class="all_report">
<div ng-repeat="data in reports">
{{reports.indexOf(data)}}
</div>
<!--<div class="date">
{{data.created_at}} <br/>
<span class="month">{{data.created_at}}</span>
</div>
<div class="status">{{data.status}}</div>-->
</div>
but it not print anything how to print in div format
I don't know how to print
I tried above but not printing
how to achieve this to print in ng-repet?

You can use ng-repeat="(key, value) in reports" to iterate over the keys-value pairs in your reports object. For your specific case, the HTML would look something like the following:
<div ng-repeat="(key, value) in reports" class="all_report">
<div>{{key}}</div>
<div ng-repeat="data in value">
<div>{{$index}}</div>
<!-- Access data from the individual report rows here -->
</div>
</div>

look I can help you with your question, but it would be better if you write the answer you expect to see from JSON, to be able to accommodate HTML, but look at angularJS with ng-repeat helps you navigate the JSON, but as long as you have Well built the JSON, it suits you a bit the div, if it's really what you need.
I leave a link where you can support
https://jptacek.com/2013/10/angularjs-introducing-ng-repeat/
$scope.test = {
"my2":[
{
"id":5,
"cuid":20,
"name":"my2",
"month":"04",
"created_at":"2018-04-01 00:00:00",
"updated_at":"2018-04-11 00:00:00",
"time":"04:32 PM",
"status":"D"
},
{
"id":4,
"cuid":20,
"name":"my2",
"month":"04",
"created_at":"2018-04-02 00:00:00",
"updated_at":"2018-04-12 00:00:00",
"time":"12:10 PM",
"status":"P"
},
],
"my":[
{
"id":44,
"cuid":21,
"name":"my",
"month":"04",
"created_at":"2018-04-12 00:00:00",
"updated_at":"2018-04-12 00:00:00",
"time":"09:08 PM",
"status":"P"
}
],
"Testing":[
{
"id":43,
"cuid":19,
"name":"Testing",
"month":"04",
"created_at":"2018-04-12 00:00:00",
"updated_at":"2018-04-12 00:00:00",
"time":"09:05 PM",
"status":"P"
}
]
}
In HTML, something like that can go...
<div ng-repeat="data in test" class="all_report">
<div ng-repeat="x in data">
{{x}}
</div>
</div>

Related

Get month from date in angularjs ng-repeat

I have an AngularJS 1.X app with a date field retrieved from a .json file. The date is being converted from a string to a date object to order the list but I need to capture the "month" part of the date to group by and for separate display but can't figure it out.
Here's my controller and HTML:
Angular Controller:
(function () {
"use strict";
angular.module("xxyyzz")
.controller("displayEventCtrl", displayEventCtrl);
function displayEventCtrl($http) {
var model = this;
model.header = "Upcoming Events";
model.events = [];
$http.get("/App/Data/eventCalendar.json")
.then(function (response) {
model.events = response.data;
console.log(model.events);
});
model.sortDate = function (event) {
var date = new Date(event.date);
return date;
}
}
})();
HTML:
<div ng-controller="displayEventCtrl as model">
<h3><i class="fa fa-calendar"></i> {{model.header}}</h3>
<div class="list-group">
<a href="#" class="list-group-item" ng-repeat="event in model.events | orderBy : -model.sortDate : true track by $index">
<div class="list-group-item-heading">
<h4>{{event.title}}</h4>
</div>
<p class="list-group-item-text">
Tuctus placerat scelerisque.
</p>
<div class="row">
<div class="col-xs-6">
<span class="small">{{event.location}}</span>
</div>
<div class="col-xs-6">
<span class="small pull-right">
{{event.startTime}} - {{event.endTime}}
</span>
</div>
</div>
<div class="row">
<div class="col-xs-9">
<span class="small">{{event.city}}, {{event.state}}</span>
</div>
<div class="col-xs-3">
<span class="small pull-right">{{event.date}}</span>
<div class="clearfix"></div>
</div>
</div>
</a>
</div>
</div>
JSON example:`
[
{
"id": 1,
"title": "Christmas Parade",
"date": "12/25/2017",
"city": "Dallas",
"state": "TX",
"location": "Galleria Mall",
"startTime": "11:00",
"endTime": "15:00"
},
{
"id": 2,
"title": "Thanksgiving Parade",
"date": "11/23/2017",
"city": "Denver",
"state": "CO",
"location": "Mile High Stadium",
"startTime": "11:00",
"endTime": "15:00"
},
{
"id": 3,
"title": "Halloween Parade",
"date": "10/31/2017",
"city": "Sleepy Hollow",
"state": "NY",
"location": "Ichabod Crane House",
"startTime": "19:00",
"endTime": "21:00"
},
{
"id": 4,
"title": "Independence Day Fireworks",
"date": "07/04/2017",
"city": "Washington",
"state": "DC",
"location": "National Mall",
"startTime": "11:00",
"endTime": "15:00"
}
]
Any help would be appreciated.
You can use js api named moment. Inject moment as dependency. You can use moment to get date in any formate you want.
moment ().get ('month');
To get the month, use the getMonth() function
var Xmas95 = new Date('December 25, 1995 23:15:30');
var month = Xmas95.getMonth();
console.log(month); // 11
My issue is that I am trying to pull the date from the array in the ng-repeat. So I can't declare the variable like above as it is part of a returned array {{event.date}}. What I need to know is how to get that date part from the nested item.
Use a custom filter to convert the text data to a Date object:
angular.module("app",[])
.filter("toDate", function() {
return function(data) {
return new Date(data);
};
})
.run(function($rootScope) {
var vm = $rootScope;
vm.Xmas95 = 'December 25, 1995 23:15:30';
})
<script src="//unpkg.com/angular/angular.js"></script>
<div ng-app="app">
Month number = {{Xmas95 | toDate | date: 'MM'}}
</div>
For more information, see
AngularJS Developer Guide - Creating Custom Filters
AngularJS date Filter API Reference

Getting RangeError: Maximum call stack size exceeded with angularjs filter

I am getting RangeError: Maximum call stack size exceeded with filter option in angularjs array of objects. Without filte option , its working fine.
HTML :
<div class="searchBar">
<input type="text" class="form-control" placeholder="Search" ng-model="searchPayment">
<i class="fa fa-search fa-2x"></i>
</div>
<div class="payment col-xs-12" ng-repeat="payment in payments | filter:{ 'name':searchPayment}">
<div class="col-xs-8">
<div class="section">
<div class="checkbox">
<label>
<input type="checkbox" ng-model="payment.checked">
<h5>[[payment.name]]</h5>
</label>
</div>
</div>
</div>
</div>
and controllrt.js :
$scope.payments = [{
"collection": "105.00",
"customerEmail": "rk#gmail.com",
"date": "10\/7\/2016 12:00:00 AM",
"lan": "JAX15E0140",
"name": "Rrts",
"passThru": "105.00",
"passThruId": "7357ac197",
"recovery": "0.00",
"source": "APTA",
"status": "0"
}, {
"collection": "6000.00",
"customerEmail": "tlt#gmail.com",
"date": "12\/7\/2016 12:00:00 AM",
"lan": "JAI47",
"name": "Test23:41:40.635",
"passThru": "6000.00",
"passThruId": "6f96d57eca9b9",
"recovery": "0.00",
"source": "ABA",
"status": "0"
}, {
"collection": "1.50",
"customerEmail": "me#gmail.com",
"date": "12\/17\/2015 12:00:00 AM",
"lan": "H132",
"name": "REPOT",
"passThru": "0.00",
"passThruId": "fbc51ae681c96",
"recovery": "400.00",
"source": "ABHTA",
"status": "0"
}, {
"collection": "2500.00",
"customerEmail": "t.e#gmail.com",
"date": "12\/18\/2016 12:00:00 AM",
"lan": "JAI1551",
"name": "Test I55.559",
"passThru": "2500.00",
"passThruId": "4beb3ad2c176e3bd",
"recovery": "0.00",
"source": "ABTA",
"status": "0"
}, {
"collection": "3500.00",
"customerEmail": "tt#gmail.com",
"date": "12\/18\/2016 12:00:00 AM",
"lan": "JAI1",
"name": "Test Indust:55.559",
"passThru": "3500.00",
"passThruId": "edb23c1e305550",
"recovery": "0.00",
"source": "AA",
"status": "0"
}]
This is what getting in console. Can anyone help to remove this error while using filter option ?

How to filter Firebase JSON using AngularJS?

I am calling my Firebase Database JSON in AngularJS and trying to filter through the code. I keep seeing Array errors like:
Error: [filter:notarray] http://errors.angularjs.org/1.4.9/filter/notarray?
My HTML:
<form>
<div class="form-group">
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-search"></i></div>
<input type="text" class="form-control" placeholder="Search" ng-model="searchTranslation">
</div>
</div>
</form>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>ID</th>
<th>English</th>
<th>Arabic</th>
<th>Status</th>
<th>Settings</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="i in translations | filter:searchTranslation track by $index">
<td>{{$index}}</td>
<td>{{i.transNameEn}}</td>
<td class="textarabic">{{i.transNameArabic}}</td>
<td class="{{i.transStatus}}">{{i.transStatus}}</td>
<td>
<a ng-href="{{url}}pages-edit-translation/{{i.transId}}"
class="btn caps btn-warning">
EDIT
</a>
</td>
</tr>
</tbody>
</table>
My JS code
// #pages-home-translation
cmsApp.controller('pages-home-translation', function ($scope, $http) {
$scope.sortType = 'English'; // set the default sort type
$scope.sortReverse = false; // set the default sort order
$scope.searchTranslation = ''; // set the default search/filter term
$http.get(firebase_url+'cms/translations.json'+randstatus).success(function(data) {
$scope.translations=data; // or data.data
});
});
My JSON:
{
"00hym5km2tf08s38fr-ivjgnsw6": {
"notes": "",
"transCreation": "11/15/2016, 4:14:07 PM",
"transId": "00hym5km2tf08s38fr-ivjgnsw6",
"transModified": "11/15/2016, 4:14:07 PM",
"transNameArabic": "استخدم كعنوان الدفع الافتراضي",
"transNameEn": "Use as my default billing address",
"transStatus": "FIXED"
},
"08zq3t9411zaketnpnwmi-ivjhzz5q": {
"notes": "",
"transCreation": "11/15/2016, 4:51:35 PM",
"transId": "08zq3t9411zaketnpnwmi-ivjhzz5q",
"transModified": "11/15/2016, 4:51:35 PM",
"transNameArabic": "احذية كرة القدم",
"transNameEn": "Football Shoes",
"transStatus": "FIXED"
},
"0aoycw0b0c9v8ov6xbt9-ivjhwnv6": {
"notes": "",
"transCreation": "11/15/2016, 4:49:00 PM",
"transId": "0aoycw0b0c9v8ov6xbt9-ivjhwnv6",
"transModified": "11/15/2016, 4:49:00 PM",
"transNameArabic": "جينز واسع",
"transNameEn": "Flared Jeans",
"transStatus": "FIXED"
}
}
Note: If I remove
<tr ng-repeat="i in translations | filter:searchTranslation track by $index">
and do this instead it works:
<tr ng-repeat="i in translations">
But clearly I wish to filter the results using the search form. Using data.data shows no errors in the console.
I have tried to do setTimeOut on the http.get and also delays so that it loads the JSON first but it is still not working.
Thanks
The problem is that the filter doesn't filter objects by default, even though ng-repeat can iterate over an object properties. Therefore there is two way out for this issue: convert the object to array before set it to your model, or you can create a custom filter (which is not much reusable) to filter over an object properties.
First
To create a custom filter you can do:
Html
<ANY ng-repeat="item in items | filterObject:myModel">
JS
angular.filter('filterObject', function () {
return function (obj, myModel) {
// filter logic, bla bla bla
};
});
Second
To convert the object into an array, you can do it on controller side (or create a helper function, service, etc.) or you can create a custom filter to do so. For example:
Html
<ANY ng-repeat="item in items | asArray | filter:myModel">
JS
.filter('asArray', function() {
return function(obj /*, addKey*/ ) {
// in case of undefined just return the same object to pass through
if (!obj) return obj;
// return an object maped as array of key as an item
return Object.keys(obj).map(function(key) {
return obj[key];
});
};
});
Using a filter to conver array into an object, you can reuse the $filter logic without having to implement a filter solution again. Therefore, I consider this better than usign a custom filter for the task.
A little less expensive approach would be converting it to an array before sending it to your model. However, you may want to keep the original property names (ids or whatever that is).
$http.get(firebase_url+'cms/translations.json'+randstatus).success(function(data) {
var myData = Object.keys(data).map(function(key) {
return obj[key];
});
$scope.translations = myData;
});
The following example implements this solution, using the second approach (there is 1 second delay simulating a server response or something to fill the translations model):
var cmsApp = angular.module('cmsApp', []);
cmsApp.filter('asArray', function() {
return function(obj /*, addKey*/ ) {
// in case of undefined just return the same object to pass through
if (!obj) return obj;
// return an object maped as array of key as an item
return Object.keys(obj).map(function(key) {
return obj[key];
});
};
});
// #pages-home-translation
cmsApp.controller('pages-home-translation', function($scope, $http, $timeout) {
$scope.sortType = 'English'; // set the default sort type
$scope.sortReverse = false; // set the default sort order
$scope.searchTranslation = ''; // set the default search/filter term
var data = {
"00hym5km2tf08s38fr-ivjgnsw6": {
"notes": "",
"transCreation": "11/15/2016, 4:14:07 PM",
"transId": "00hym5km2tf08s38fr-ivjgnsw6",
"transModified": "11/15/2016, 4:14:07 PM",
"transNameArabic": "استخدم كعنوان الدفع الافتراضي",
"transNameEn": "Use as my default billing address",
"transStatus": "FIXED"
},
"08zq3t9411zaketnpnwmi-ivjhzz5q": {
"notes": "",
"transCreation": "11/15/2016, 4:51:35 PM",
"transId": "08zq3t9411zaketnpnwmi-ivjhzz5q",
"transModified": "11/15/2016, 4:51:35 PM",
"transNameArabic": "احذية كرة القدم",
"transNameEn": "Football Shoes",
"transStatus": "FIXED"
},
"0aoycw0b0c9v8ov6xbt9-ivjhwnv6": {
"notes": "",
"transCreation": "11/15/2016, 4:49:00 PM",
"transId": "0aoycw0b0c9v8ov6xbt9-ivjhwnv6",
"transModified": "11/15/2016, 4:49:00 PM",
"transNameArabic": "جينز واسع",
"transNameEn": "Flared Jeans",
"transStatus": "FIXED"
}
};
$timeout(function() {
$scope.translations = data; // or data.data
}, 1500);
});
angular.element(document).ready(function() {
angular.bootstrap(document, ['cmsApp']);
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.js"></script>
<div ng-controller="pages-home-translation">
<form>
<div class="form-group">
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-search"></i>
</div>
<input type="text" class="form-control" placeholder="Search" ng-model="searchTranslation">
</div>
</div>
</form>
<table class="table table-bordered table-striped" border="1" cellpadding="4" style="border-collapse: collapse;">
<thead>
<tr>
<th>ID</th>
<th>English</th>
<th>Arabic</th>
<th>Status</th>
<th>Settings</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="i in translations | asArray | filter:searchTranslation track by $index">
<td>{{$index}}</td>
<td>{{i.transNameEn}}</td>
<td class="textarabic">{{i.transNameArabic}}</td>
<td class="{{i.transStatus}}">{{i.transStatus}}</td>
<td>
<a ng-href="{{url}}pages-edit-translation/{{i.transId}}" class="btn caps btn-warning">EDIT</a>
</td>
</tr>
</tbody>
</table>
</div>
Some changes needed as per your code. First of all $scope.translations should be an array but as per your JSON it's not an array. ng-repeat directive only accepts an array to repeat the data.
Your $scope.translations should be like that as per your HTML Structure :
$scope.translations = [
{
"notes": "",
"transCreation": "11/15/2016, 4:14:07 PM",
"transId": "00hym5km2tf08s38fr-ivjgnsw6",
"transModified": "11/15/2016, 4:14:07 PM",
"transNameArabic": "استخدم كعنوان الدفع الافتراضي",
"transNameEn": "Use as my default billing address",
"transStatus": "FIXED"
},
{
"notes": "",
"transCreation": "11/15/2016, 4:51:35 PM",
"transId": "08zq3t9411zaketnpnwmi-ivjhzz5q",
"transModified": "11/15/2016, 4:51:35 PM",
"transNameArabic": "احذية كرة القدم",
"transNameEn": "Football Shoes",
"transStatus": "FIXED"
},
{
"notes": "",
"transCreation": "11/15/2016, 4:49:00 PM",
"transId": "0aoycw0b0c9v8ov6xbt9-ivjhwnv6",
"transModified": "11/15/2016, 4:49:00 PM",
"transNameArabic": "جينز واسع",
"transNameEn": "Flared Jeans",
"transStatus": "FIXED"
}
];
Working demo :
var cmsApp = angular.module('myApp',[]);
cmsApp.controller('pages-home-translation', function ($scope, $http) {
$scope.sortType = 'English'; // set the default sort type
$scope.sortReverse = false; // set the default sort order
$scope.searchTranslation = ''; // set the default
$scope.translations = [
{
"notes": "",
"transCreation": "11/15/2016, 4:14:07 PM",
"transId": "00hym5km2tf08s38fr-ivjgnsw6",
"transModified": "11/15/2016, 4:14:07 PM",
"transNameArabic": "استخدم كعنوان الدفع الافتراضي",
"transNameEn": "Use as my default billing address",
"transStatus": "FIXED"
},
{
"notes": "",
"transCreation": "11/15/2016, 4:51:35 PM",
"transId": "08zq3t9411zaketnpnwmi-ivjhzz5q",
"transModified": "11/15/2016, 4:51:35 PM",
"transNameArabic": "احذية كرة القدم",
"transNameEn": "Football Shoes",
"transStatus": "FIXED"
},
{
"notes": "",
"transCreation": "11/15/2016, 4:49:00 PM",
"transId": "0aoycw0b0c9v8ov6xbt9-ivjhwnv6",
"transModified": "11/15/2016, 4:49:00 PM",
"transNameArabic": "جينز واسع",
"transNameEn": "Flared Jeans",
"transStatus": "FIXED"
}
];
});
table,th,td {
border:1px solid black;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="pages-home-translation">
<form>
<div class="form-group">
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-search"></i></div>
<input type="text" class="form-control" placeholder="Search" ng-model="searchTranslation">
</div>
</div>
</form>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>ID</th>
<th>English</th>
<th>Arabic</th>
<th>Status</th>
<th>Settings</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="i in translations | filter:searchTranslation">
<td>{{$index}}</td>
<td>{{i.transNameEn}}</td>
<td class="textarabic">{{i.transNameArabic}}</td>
<td class="{{i.transStatus}}">{{i.transStatus}}</td>
<td>
<a ng-href="{{url}}pages-edit-translation/{{i.transId}}"
class="btn caps btn-warning">
EDIT
</a>
</td>
</tr>
</tbody>
</table>
</div>

How to display images dynamically in slider on clicking a particular image using angular js

we have a problem in displaying images in slider dynamically.i.e, when we click on a particular image in list it must be displayed in the slider.We are getting the images from a json file.The problem is the images are not getting displayed in slider,but the click functionality is working.Clicked image ids are shown in console too.
Here is the code:
enter code here
JSON:
[{
"menuId": "01",
"menuItem": "manuchuriya",
"menuImage": "img/Categoryimages/manchuria.jpe",
"items": [{
"id": "001",
"itemName": "Noodles",
"itemImage": "item_images/aloo_chaat.jpg",
"price": "$30",
"description": "Add water or veg stock.mix well and add let the sauce simmer for 1-2 minutes.add the cornflour paste to thicken the sauce.Thicken the sauceto your desired consistency.add vinegar, salt, sugar and the fried veg balls.serve veg manchurian garnished with spring onion greens."
},
{
"id": "002",
"itemName": "Noodles",
"itemImage": "item_images/samosa.jpg",
"price": "$20",
"description": "Add water or veg stock.mix well and add let the sauce simmer for 1-2 minutes.add the cornflour paste to thicken the sauce.Thicken the sauceto your desired consistency.add vinegar, salt, sugar and the fried veg balls.serve veg manchurian garnished with spring onion greens."
}]
},
{
"menuId": "02",
"menuItem": "icecream",
"menuImage": "img/Categoryimages/ice-cream.jpg",
"items": [{
"id": "001",
"itemName": "salad",
"itemImage": "item_images/fruit_juice.jpg",
"price": "$40",
"description":"Add ghee, salt and carom seeds in maida. Mix all ingredients. Cut paneer into small chunks.Peel potatoes and mash them Knead the dough until it becomes soft. Take little amount of dough and roll it."
},
{
"id": "002",
"itemName": "salad",
"itemImage": "item_images/bevarages.jpg",
"price": "$20",
"description":"Add ghee, salt and carom seeds in maida. Mix all ingredients. Cut paneer into small chunks.Peel potatoes and mash them Knead the dough until it becomes soft. Take little amount of dough and roll it."
}]
},
{
"menuId": "03",
"menuItem": "franke",
"menuImage": "img/Categoryimages/samosas.jpg",
"items": [{
"id": "001",
"itemName": "salad",
"itemImage": "item_images/frankie.jpg",
"price": "$30",
"description":"Add ghee, salt and carom seeds in maida. Mix all ingredients. Cut paneer into small chunks.Peel potatoes and mash them Knead the dough until it becomes soft. Take little amount of dough and roll it."
},
{
"id": "002",
"itemName": "salad",
"itemImage": "item_images/aloo_chaat.jpg",
"price": "$40",
"description":"Add ghee, salt and carom seeds in maida. Mix all ingredients. Cut paneer into small chunks.Peel potatoes and mash them Knead the dough until it becomes soft. Take little amount of dough and roll it."
}]
}]
Controller:
angular.module('starter')
.controller('menuitemCtrl', function ($scope,$state,$q,$stateParams,menuService) {
console.log($stateParams.id);
$scope.id = $stateParams.id;
var getMenuList = function(){
menuService.getMenuListData()
.then(function sucessCallback(response){
$scope.menulists = response;
console.log("menu");
for(var i in $scope.menulists.items)
{
if($scope.menulists[i].items[i].id === $scope.id)
{
$scope.SliderItem=$scope.menulists[i].items[i];
console.log(SliderItem);
}
}
function errorCallback(error){
return $q.reject(error);
});
};
getMenuList();
});
HTML Code:
<ion-view class="view-styles-item" style="margin-left: 24%">
<ion-content scroll="false">
<ion-slides options="options" slider="data.slider">
<ion-slide-page ng-repeat="item in SliderItem.items">
<div class="row">
<img src="img/menuitem/{{item.itemImage}}" style="width: 52%;">
</div>
<div class="row">
<p>{{item.description}}</p>
<p>{{item.price}}</p>
</div>
</ion-slide-page>
</ion-slides>
</ion-content>
Click event HTML Code:
<ion-view class="view-styles-menu" >
<ion-content >
<div ng-repeat="item in SelectedMenu.items" >
<div class="row menu-row">
<div class="col">
<!-- <a href="#/tab/home/item?id={{item.id}}"> -->
<img src="/img/menuitem/{{item.itemImage}}" class="menu-img_styles" ng-click="goToMenuItem(item.id)">
</div>
<div class="col">
{{item.itemName}}
</div>
<div class="col">
{{item.price}}
</div>
</div>
</div>
<ion-nav-view name="tab-item"></ion-nav-view>
</ion-content>
<div class="divider"></div>
</ion-view>
Controller:
$scope.goToMenuItem = function(paramId){
$state.go('tab.home.menu.item',{id:paramId});
};

iterate hasmap with ng-repeat. Hashmap with array as value

How can i iterate below JSON response from server using angularJS on UI using ng-repeat?
$scope.data = {
"Home Needs": [{
"id": 11,
"itemName": "PARLE G 500 Grams",
"itemPrice": 50,
"minSellPrice": 45,
"discount": 0,
"store": "Home Needs"
}],
"SRI SAI Store": [{
"id": 1,
"itemName": "PARLE G 500 Grams",
"itemPrice": 50,
"minSellPrice": 45,
"discount": 0,
"store": "SRI SAI Store"
}],
"Ashirwad": [{
"id": 10,
"itemName": "PARLE G 500 Grams",
"itemPrice": 50,
"minSellPrice": 46,
"discount": 0,
"store": "Ashirwad"
}]
}
Can anyone help me with a jsfiddle please or a pointer please?
thanks
Kindly check Jsfiddle
<div ng-app>
<div ng-controller="ClickToEditCtrl">
<p>Your Data:</p>
<ul ng-repeat="(key, value) in data">
name: {{key}}
<li ng-repeat="v in value">
{{v.id}},
{{v.itemName}},
{{v.itemPrice}},
{{v.minSellPrice}},
{{v.discount}},
{{v.store}}
</li>
</ul>
</div>
</div>
you can modified as u required. I hope this might help.

Resources