Angular.js - Data from AJAX request as a ng-repeat collection
Date : March 29 2020, 07:55 AM
Does that help Came out, that @luacassus 's answer about track by option of ng-repeat directive was very helpful but didn't solve my problem. track by function was adding new invoices coming from server, but some problem with clearing inactive invoices occured. So, this my solution of the problem: function change(scope, newData) {
if (!scope.invoices) {
scope.invoices = [];
jQuery.extend(true, scope.invoices, newData)
}
// Search and update from server invoices that are presented in scope.invoices
for( var i = 0; i < scope.invoices.length; i++){
var isInvoiceFound = false;
for( var j = 0; j < newData.length; j++) {
if( scope.invoices[i] && scope.invoices[i].id && scope.invoices[i].id == newData[j].id ) {
isInvoiceFound = true;
jQuery.extend(true, scope.invoices[i], newData[j])
}
}
if( !isInvoiceFound ) scope.invoices.splice(i, 1);
}
// Search and add invoices that came form server, but are nor presented in scope.invoices
for( var j = 0; j < newData.length; j++){
var isInvoiceFound = false;
for( var i = 0; i < scope.invoices.length; i++) {
if( scope.invoices[i] && scope.invoices[i].id && scope.invoices[i].id == newData[j].id ) {
isInvoiceFound = true;
}
}
if( !isInvoiceFound ) scope.invoices.push(newData[j]);
}
}
|
angular ng-repeat - each item in collection repeating per number of items in collection (weird)
Date : March 29 2020, 07:55 AM
seems to work fine try removing one of the angular references either in Frameworks and Extensions or External resources.
|
angular.js ng-repeat - check if conditional is true then use another collection
Date : March 29 2020, 07:55 AM
I hope this helps you . I'm wondering is it possible to check what collection to use inside ng-repeat? , Try this ... In your controller $scope.getDataSource=function(condition){
if(condition){ return dataSource1; }
return dataSource2;
};
ng-repeat="book in getDataSource(/*condition*/)
ng-repeat="book in {true: adultBooks, false: childBooks}[list==='adultBooks']"
<li ng-repeat="book in {true: childBooks, false:adultBooks}[list==='childBooks']">{{book.name}
|
How do I filter an Angular ng-repeat collection with a function?
Date : March 29 2020, 07:55 AM
this will help I want to filter a list of items in an ng-repeat using | filter:function. The docs have an example that filters the list based on what's been entered into an input box. here is a modification of it where I am attempting to limit the list of friends to just the boys. How do I get that to work? , You can use it like this angular.module('ngRepeat', ['ngAnimate'])
.controller('repeatController', function($scope) {
$scope.friends = [
{name:'John', age:25, gender:'boy'},
{name:'Jessie', age:30, gender:'girl'},
{name:'Johanna', age:28, gender:'girl'},
{name:'Joy', age:15, gender:'girl'},
{name:'Mary', age:28, gender:'girl'},
{name:'Peter', age:95, gender:'boy'},
{name:'Sebastian', age:50, gender:'boy'},
{name:'Erika', age:27, gender:'girl'},
{name:'Patrick', age:40, gender:'boy'},
{name:'Samantha', age:60, gender:'girl'}
];
$scope.justBoys = function(item, index, array) {
console.log(item)
return item.gender==='boy';
}
});
|
collection-repeat with angular component, what is happening?
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Lost 3 hours to figure out this
|