我使用 Angucomplete Alt 指令来进行自动完成。 到目前为止它工作正常,但我想向我的服务器发出特定请求。 /搜索/用户/名称?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>
换句话说,我想在将请求发送到我的服务器之前将所有空格更改为点。
提前谢谢您!
最佳答案
您可以使用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>
在你的 Controller 中:
$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});
}
关于javascript - Angucomplete Alt url 远程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37274566/