2015-08-26 105 views
0

我的功能是使用query()方法來顯示所有任務。問題在於它指的是users/tasks?status=completed。我需要users/:user_id/tasks?status=completed。 我該如何解決它?.query()呈現錯誤路徑

var app = angular.module('Todolist', ['ngResource']); 

    app.factory('Task', [ 
    '$resource', function($resource) { 
     return $resource('/users/:user_id/tasks/', {id: '@id'}, {update: {method: 'PUT'}}); 
    } 
    ]); 

    app.controller('TasksCtrl', [ 
    '$scope', 'Task', function($scope, Task) { 

     $scope.user = current_user 

     $scope.tasks = Task.query(
     status: 'incompleted' 
    ); 

    } 
    } 
    ]); 

回答

1

請更新您控制器

app.controller('TasksCtrl', [ 
    '$scope', 'Task', function($scope, Task) { 
    $scope.user = null; //current_user please define this variable it will cause for undefined error 
    $scope.tasks = Task.query({status: 'completed', user_id : 12}); //'12' is user id , you can pass dynamically 

}]); 

工廠代碼:

app..factory('Task', [ 
    '$resource', function($resource) { 
     return $resource('/users/:user_id/tasks/', 
     {user_id: '@user_id'}, 
     {update: {method: 'PUT'}}); 
    } 
]); 

Working plunker

+0

@PankajParkar請參閱你的答案 –

+0

我刪除我的downvote,並回答過我的意見..不想阻止任何人:)你的印象深刻幼稚的性質。哈哈:D –