I'm just messing around with angular a bit and I built a simple task API. 
This api has assigned and accepted tasks. Now when building the app I have 
these routes:

TaskManager.config(['$routeProvider',
    function($routeProvider) {
        $routeProvider.
            when('/:username/assigned-tasks', {
                templateUrl: 'app/partials/assigned-tasks.html',
                controller: 'TaskController'
            }).
            when('/:username/accepted-tasks', {
                templateUrl: 'app/partials/assigned-tasks.html',
                controller: 'TaskController'
            }).
            otherwise({
                 redirectTo: '/'
            });
   }]);

And here is the task controller I started building and then realized this 
was not going to work

TaskManager.controller('TaskController', ['$scope', 'AssignedTasksService', 
function($scope, AssignedTasksService){
    $scope.tasks = [];

    loadAssignedTasks();

    function applyRemoteData( Tasks ) {
        $scope.tasks = Tasks;
    }

    function loadAssignedTasks() {

        AssignedTasksService.getAssignedTasks()
            .then(
            function( tasks ) {
                applyRemoteData( tasks );
            }
        );
    }}]);

The getAssignedTasks funciton is just a function that runs a http get 
request to the api url and either returns and error or the api data

now as you can see the assigned tasks are automatically loaded once it hits 
the TaskController which is obviously a problem since I need to also be 
able to get accepted tasks. Now do I need to create a separate controller 
for accepted tasks or is there a way for maybe me to check the url from the 
controller and from there I can decide if I want to run the 
loadAssignedTasks function or the loadAcceptedTasks (which I haven't 
created yet). but it would just do the same thing as the loadAssignedTasks 
function but for the accepted tasks

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to