Answer the question
In order to leave comments, you need to log in
How to add layered array to JSON from Angular controller?
I have a json file which is used as a db. It has an array with objects (single-level). Each object has an id and parentId, based on which the dependency tree should be built. I need to take data from an array and build another array in the same file, but with attachments. Those. there will be one parent object, it has several children, and these children have their own children.
There are such services:
.service('oneFactory', ['$resource', 'baseURL', function($resource, baseURL) {
this.getOne = function() {
return $resource(baseURL + 'firstArray');
};
}])
.service('twoFactory', ['$resource', 'baseURL', function($resource, baseURL) {
this.getTwo = function() {
return $resource(baseURL + 'secondArray');
};
}]);
.controller('BadController', ['$scope', 'oneFactory', 'twoFactory', function($scope, oneFactory, twoFactory) {
$scope.firstArray = oneFactory.getOne().query(
function(response) {
$scope.firstArray = response;
}
);
$scope.sendTwo = function() {
for (var i = 0; i < firstArray.length; i++) {
if (i.parentId === 1) {
twoFactory.getTwo().save();
}
...
}
};
}]);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question