I have a model. The model has lot's of potential nested arrays. The item is a task and I can add a category to it for example.
When I'm doing a new .POST how do I get the item's from the nested array into the model? I've looked through the Restangular docs which says it's easy to deal with nested models (which is why I chose Restangular) but I'm not seeing an easy way to do it. I know I'm just not seeing what is probably right infront of my face, so I'm asking here so someone can show me the "right" way to do it.
Here is the controller that I've been working on. I can't figure out how to get the category into the array for a task. Do I need a ng-click or something that passes the resource URL into the array with a .push() in the controller?
TaskCtrls.controller('TaskAddCtrl', ['$scope', 'Restangular', '$state', 'growl',
function($scope, Restangular, $state, growl) {
// Adding in the need meta objects
Restangular.all('category').getList().then(function(categories){
$scope.categories = categories;
}, function(response) {
growl.addErrorMessage("There was an error with status code: ", response.status);
});
$scope.task = {} // do I add the category here? And how do I do that?
$scope.addNote = function() {
Restangular.all('task/').post($scope.task).then(function(task){
console.log(task);
growl.addSuccessMessage("Your task has been added!");
$state.go('tasks.list');
}, function(response) {
console.log(response.data);
growl.addErrorMessage("There was an error with status code: ", response.status);
});
}
}
]);