I have a json file, I would like to place '?' insert the numbers 1 ... 10
{
"Daty": [{
"Data": "2016-02-13",
"L1": [],
"L2": [],
"L3": [],
"L4": [],
"L5": [],
"L6": [],
"L7": [],
"L8": [],
"L9": [],
"L10": [],
"Suma": 0
} .........
}]
}
In html:
<tr ng-repeat="x in Daty" > <td><B>{{x.Data}}</B></td><td ng-repeat="y in [1,2,3,4,5,6,7,8,9,10]">{{x.L??????[0]}}</td><td>{{x.L???????[0]}}</td><td>{{x.L??????[0]}}</td>
I would like to place '?' insert the numbers 1 ... 10
You can try to access the field with [] notation like this:
<tr ng-repeat="x in Daty" > <td><B>{{x.Data}}</B></td><td ng-repeat="y in [1,2,3,4,5,6,7,8,9,10]">{{x['L'+y][0]}}</td><td>{{x['L'+y][0]}}</td><td>{{x['L'+y][0]}}</td>
Simply use below concatenation, which accessing object from array.
<tr ng-repeat="x in Daty">
<td><B>{{x.Data}}</B></td>
<td ng-repeat="y in [1,2,3,4,5,6,7,8,9,10]">{{x['L'+ y][0]}}</td>
</tr>
Related
Can someone explain to me why this doesn't loop?
If I pre napIncident it gives null.
My code
<tr ng-repeat="napIncident in vm.NapIncidents">
<pre>{{vm.NapIncidents | json}}</pre>
<td>
{{napIncident.Incident}}
</td>
Pre output
[
{
"NapIncident": {
"Incident": "Zahlunsverbindungen ändern",
"IncidentID": "0002724285",
"NapID": "4214",
"NapStatus": "erfasst",
"Username": "silvat",
"NumberOfApprovers": "2",
"RecordDate": "12-12-2018",
"CheckerInformationList": [
{
"CheckerInformation": {
"Checker": "silvat",
"Date": "21-09-2018",
"TimeOfDay": "12:12:36",
"CheckerInfo": "Something",
"CheckerInfoText": "Something else"
}
}
],
"Alterations": [
{
"Alteration": {
"Field": "IBAN",
"OldValue": "DE12345",
"NewValue": "DE54321"
}
}
]
}
}
]
you have to access to your item . In your case is napIncident. Check your html part you will find ng repeat "NapIncident in vm.NapIncidents" .
To access to the details {{NapIncident.NapIncident.Incident}}
When using ng-repeat you map each item to a temporary variable, and when you have an array of named literals i.e array of NapIncident: {...} you must refer to NapIncident as a property :
<tr ng-repeat="item in vm.NapIncidents">
<td>
{{ item.NapIncident.Incident }}
</td>
<td>
{{ item.NapIncident.IncidentID }}
</td>
</tr>
and so on.
I have an object as follows:
scope.items = {
"poor-John-1": {
"_id": "poor-John-1",
"name": "poor-John-1",
"sName": "room-poor-John-2"
},
"poor-John-2": {
"_id": "poor-John-2",
"name": "poor-John-2",
"sName": "room-poor-John-2"
}
}
I have rendered the object in the following way
<tr ng-repeat="item in items | orderObjectBy: '_id' track by item._id" ng-class="getStyle(item, next_item)"><td>{{item.sName}}</td></tr>
What I want to do is, pass, the current and next_item to the getStyle function, since its not an array, $index is not pointing the value. I have data in object.
Maybe you can do this with
$scope.keys = Object.keys($scope.items) // put keys on scope
// get next from keys
<tr ng-repeat="(key, item) in items track by item._id" ng-class="getStyle(item, items[keys[$index +1]])">
<td>{{key}}</td>
<td>{{item.name}}</td>
<td>next : {{items[keys[$index +1]]}}</td>
</tr>
Look this, tell me if it's what you want https://plnkr.co/edit/GCNmWb9Qv2mntqTnGsX1?p=preview
I'd like to be able to sort by whether a variable is true or false.
Let's say we have a variable like so:
groups = {
{ name: 'first', value: true },
{ name: 'second', value: false },
{ name: 'third', value: true },
{ name: 'fourth', value: false }
}
And we can loop through it like so:
<div ng-repeat="group in groups">
{{group.name}} {{group.value}}
</div>
Which will give you the following:
first true
second false
third true
fourth false
But if I wanted to sort by a boolean value then I could do this:
<div ng-repeat="group in groups | filter:{value:true}">
{{group.name}} {{group.value}}
</div>
<div ng-repeat="group in groups | filter:{value:false}">
{{group.name}} {{group.value}}
</div>
Which would give me the following output (which I want):
first true
third true
second false
fourth false
Is there a way to do this using orderBy or filter in a single ng-repeat?
orderBy accepts and sorts by booleans.
Order the repeated element by the the 'value' property of 'group':
ng-repeat="group in groups | orderBy: 'value'"
This will reverse the order:
ng-repeat="group in groups | orderBy: '-value'"
If you would like to also sort by the 'name' property of 'group':
ng-repeat="group in groups | orderBy: ['value','name']"
use variable name instead obeject
orderBy:'Event':false
you will get the desired output like -
first true
third true
second false
fourth false
I have data which is represented as column names, row names and values for a row/column pair. It looks like this:
cols = ['A', 'B', 'C', 'D'];
rows = ['1', '2', '3', '4'];
data = [
{row: '1', col:'A', value: 'a'},
{row: '2', col:'C', value: 'b'},
{row: '3', col:'B', value: 'c'}
];
How do I make this appear in table like this? I am using Angular 1.4.
A B C D
1 a
2 b
3 c
4
My data size is limited, don't expect it to be more than 50-100 entries in data.
Change your data object to a dictionary:
data = [
{row: '1', col:'A', value: 'a'},
{row: '2', col:'C', value: 'b'},
{row: '3', col:'B', value: 'c'}
];
becomes:
data = {'A1' : 'a', 'C2' : 'b', 'B3' : 'c'}..
then do a double ng-repeat loop:
<div ng-repeat="col in cols">
<div ng-repeat="row in rows">
{{ data[row + col] == null ? " " : data[row + col] }}
disclaimer: this is untested, and my angular syntax may be incorrect, but I hope you get the idea.
Since I was limited to not being able to reformat the data and the actual data was a somewhat more complicated than this I ended up writing a filter. My html looks like this:
<div>
<table>
<tr><td></td>
<td ng-repeat="col in cols">{{ col }}</td>
</tr>
<tr ng-repeat="row is rows">
<td>{{ row }}</td>
<td ng-repeat="col in cols">
<div ng-repeat="obj in data | findRowCol:row:col">
{{ obj.value }}
</div>
</td>
</tr>
</table>
</div>
I borrowed from KayakDave's answer here for my filter.
app.filter('findRowCol', function() {
return function(data, row, col) {
result = [];
data.forEach(function(el) {
if(el.row === row && el.col === col)
result.push(el);
});
return result;
}
});
Since data is not expected to be ordered in any particular way this can have a O(N^3) performance, so not very nice solution.
I have a listing using ng-repeat with a search for two available parameters (month and state).
If I make a search, I get a ng-repeat error found duplicates.
Can not understand why if in both cases the JSON data have the same structure (just the values will change).
I have these ng-repeats: item in data and nested inside : uniqueitem in item
I've tried to use track by $index but it loops for every single character, and for item.index or item.label1 but triggers the found duplicates erros again.
Here is my loop using ng-repeat.
<tbody ng-repeat="item in data">
<tr ng-repeat="uniqueitem in item">
<td>
{{uniqueitem.label1 | number}}
</td>
<td>
{{uniqueitem.label2 | number}}
</td>
My JSON has this structure :
[
{
"index": 0,
"label1": "Initials",
"label2": "2",
"label3": "18",
"label4": "12",
"label5": 150,
"label6": "30",
"label7": 60,
"label5A": "v",
"label7A": "r"
},
{
"index": 1,
"label1": "Others",
"label2": 5485,
"label3": 27289,
"label4": 37776,
"label5": 72.23,
"label6": 91949,
"label7": 29.67,
"label5A": "r",
"label7A": "r"
},
....
]
Just works !
Inside
$http.post(ApiEndpoint.url,$scope.formData).success(function(data) {
Instead of this line :
$scope.data = JSON.stringify(data);
I add these lines :
var acp = {};
acp.resultdata = [ data ];
$scope.data = acp.resultdata;
I will replicate in a Plunkr, can not say why JSON.stringify causes this behavior.