繁体   English   中英

调用api时不断出现400错误(错误请求)

[英]Keep getting 400 error(Bad Request) while calling an api

我正在呼叫get 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的值。

谁能告诉我为什么我不断收到此错误?

我认为您对角度路由URL和API调用URL有误解。

您的http URL格式应为

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM