2

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);
            });
        }
    }
]);
2
  • does your category list bind to a select options or what? don't you do anything with categories on html side? and what is your task object look like? I cant see your problem here? Commented Mar 9, 2014 at 19:14
  • That is partly what I'm trying to figure out. But for now, each category is in a a href in a list. So I can pass parameters via an ng-click or something like that. The task object has a foreign key to the category in the API. Commented Mar 9, 2014 at 22:43

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.