简体   繁体   English

无法在Angular的http get请求中插入字符串

[英]Can not insert a string in a http get request in Angular

In the input field specific id will be typed and saved inside searchText : 在输入字段中,将输入特定ID,并将其保存在searchText

<form class="input-group" ng-submit="getMainData()">
  <input type="text" class="form-control" ng-model="searchText"  placeholder=" Type KvK-nummer and Press Enter" id="typehead">
</form>

and when press enter it will get this function from the controller 当按下回车键时,它将从控制器获得此功能

$scope.getMainData = function(){    
 $http.get("http://localhost:8091/odata/dll-poc-dv/Account(':searchText')")
        .success(function(data){
            $scope.allData = data;
            $scope.getData = $scope.allData.d.results;
        });
    };

What I want to achieve is the searchText typed in the input to be passed as parameter inside the brackets (':searchText') of get the relevant data. 我要实现的是在输入中键入searchText ,以将其作为获取相关数据的方括号(':searchText')中的参数进行传递。 A valid URL for getting the data looks like this: http://localhost:8091/odata/dll-poc-dv/Account('41-125061-0000') 用于获取数据的有效URL如下所示: http://localhost:8091/odata/dll-poc-dv/Account('41-125061-0000')

Use + operator for concatenation of variables. 使用+运算符来连接变量。 Also, use $scope.searchText . 另外,使用$scope.searchText

$http.get("http://localhost:8091/odata/dll-poc-dv/Account('" + $scope.searchText + "')")

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

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