2015-05-29 81 views
0

我從我的REST答案400錯誤的請求 - 結果= < 400錯誤的請求>如何獲得變量

,我想表明這個錯誤的用戶使用angularJS。

我有機能的研究在控制器

$scope.update = function (id) { 
       Topic.get({id: id}, function (result) { 
        $scope.name = result; 
        $('#saveTopicModal').modal('show'); 
        console.log(result); 
       }); 
      }; 

請幫助 - 如何在某個變量出現錯誤,然後顯示該變量。 謝謝

+0

等於什麼是'''id'''? –

+0

id - itsInterger - .get方法 –

回答

0

要訪問錯誤,您必須定義一個錯誤處理程序,如角度$資源API的說明中所述。

    $scope.error = error; 
$scope.update = function (id) { 
       Topic.get({id: id}, function (result) { 
        $scope.name = result; 
        $('#saveTopicModal').modal('show'); 
        console.log(result); 
       }, function (error) {       
        console.log(error); 
        $scope.error = error; 
       }); 
      }; 
+0

控制檯顯示PUT http .... 400(錯誤請求),但如何將它放在vatiable中? –