Angucomplete Alt url remote

时间:2016-05-17 11:16:33

标签: javascript angularjs html5 angularjs-directive

i use Angucomplete Alt directive for making autocomplete. it work fine till now , but i want to make a specific request to my server. /search/users/name?s=

<div angucomplete-alt
             id="input-name"
             placeholder="Name"
             pause="50"
             search-fields="name"
             remote-url=/users/name?s=
             title-field="name"
             minlength="3"
             match-class="angucomplete-match">
        </div>

In Other word, i want to change all spaces to dot before sending the Request to my Server.

Thank you in Advance !

2 个答案:

答案 0 :(得分:2)

您可以使用remote-api-handle选项在将字符串发送到服务器之前对其进行修改。

<div angucomplete-alt
         id="input-name"
         placeholder="Name"
         pause="50"
         search-fields="name"
         remote-url-handler="searchAPI"
         title-field="name"
         minlength="3"
         match-class="angucomplete-match">
    </div>

在您的控制器中:

$scope.searchAPI = function(userInputString, timeoutPromise) {
  //Modify input before it gets sent to the server
  userInputString = userInputString.replace(' ', '.');
  return $http.post('/users/name', {s: userInputString}, {timeout: timeoutPromise});
}

答案 1 :(得分:0)

使用remote-api-handler:

<angucomplete-alt
             id="input-name"
             placeholder="Name"
             pause="50"
             search-fields="name"
             remote-api-handler="searchAPI"
             title-field="name"
             minlength="3"
             match-class="angucomplete-match" />