2015-10-20 49 views
0

我正在使用nodejs loopback應用程序。我有一個用戶已經登錄,並且一項操作要求此用戶找到userById並更新一個字段。登錄後不能更新另一個用戶的詳細信息

 $scope.user = User.findById({ 
      id: sender.id 
     }); 

    $scope.user.supplierId = currUserId; 

    $scope.user.$save(); 

但它沒有按要求工作。

,我得到以下錯誤:

PUT http://localhost:5000/api/users 401 (Unauthorized) 
GET http://localhost:5000/api/AuthProviders/count 401 (Unauthorized) 
401 while on router on login path 
POST http://localhost:5000/api/users/login?include=user 400 (Bad Request) 

任何幫助將不勝感激。 感謝

+0

你使用他們提供的angularjs或angular sdk嗎? –

+0

我正在使用AngularJS – georgian98

+0

您不能使用模型來訪問具有常規angularjs代碼的休息終端。不過,您可以使用角度http訪問它們。我會發布答案。 –

回答

0

對於findById操作:

var url = 'http://localhost:3000/api/User/' + sender.id + '?access_token=h9vpJ94zqN199ENWx' 
$http({ 
    method: 'GET', 
    url: url 
}).then(function successCallback(response) { 
    console.log(response); 
}, function errorCallback(error) { 
    throw error; 
}); 

否則,你可以使用Angular SDK這使得它更清潔。

+0

感謝Vishal延長您的幫助。在建模方面存在缺陷,現在糾正了所有問題並且一切正常。 – georgian98