2017-01-10 95 views
0

我打電話的獲取API: -也能收到400錯誤(錯誤請求),同時調用API

function getvalue() { 
    return $http({ 
     method: 'GET', 
     url: '/api/value/:number' 
    }); 
} 

我打電話它在我的指令:

(function() { 
    'use strict'; 
    angular.module('myApp.components') 
     .directive('product', product); 

product.$inject = ['$http','$timeout','ApiServices']; 

function product($http, $timeout, ApiServices) { 
    return { 
     restrict: 'EA', 
     scope: { 
     }, 

     link: function (scope, el, attrs) { 
      scope.product = {}; 

       scope.getproductvalue = function() { 
        ApiServices.getproductvalue().then(
         function (response) { 
         scope.product.value = scope.product.a + " " +scope.product.b + " " +scope.product.c; 
         }); 
       }; 
       scope.getproductvalue(); 
     }, 
     templateUrl: 'js/components/misc/product.html' 
    }; 
    } 

})(); 

我不斷收到此錯誤: -

GET http://localhost:3001/api/product/ 400 (Bad Request) 

我從不同的API獲取a,b,c的值。

有誰能告訴我爲什麼我一直收到這個錯誤?

+0

壞請求指─你的要求的內容是完全一樣的API期待。因此,請首先檢查進行API調用所需的格式。 ':號碼'檢查是**字符串**還是**號碼**? –

+0

您在API中有getvalue(),但是您在指令中調用getproductvalue()。 – rrd

+0

10.4.1 400錯誤請求 由於格式錯誤,服務器無法理解請求。客戶端不應該在沒有修改的情況下重複請求。 –

回答

0

我認爲你對角度路由URL和API調用URL有誤解。

你的HTTP URL格式應該是

url: '/api/value ? number = '+18 
+0

應該是:-url:'/ api/value /:number'或url:'/ api/value /'+數字 –

相關問題