Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/471.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 跟踪用户输入并提供单词补全-角度_Javascript_Php_Angularjs_Ajax - Fatal编程技术网

Javascript 跟踪用户输入并提供单词补全-角度

Javascript 跟踪用户输入并提供单词补全-角度,javascript,php,angularjs,ajax,Javascript,Php,Angularjs,Ajax,我是新来的,我需要一些帮助。 假设我有一个包含数字列表的数据库,我想用这个列表来完成单词 假设这是我的表格: <!-- FORM --> <form> <!-- CODE --> <label>code</label> <input type="text" name="codeInput

我是新来的,我需要一些帮助。 假设我有一个包含数字列表的数据库,我想用这个列表来完成单词

假设这是我的表格:

          <!-- FORM -->
          <form>

                <!-- CODE -->
                  <label>code</label>
                  <input type="text" name="codeInput" placeholder="please insert your code..." >

                <!-- SUBMIT BUTTON -->
                <button type="submit" >Submit
                </button>
         </form>
我就是不知道如何连接所有组件。

方法1:

绑定到输入元素:

<input ng-model="yourValue">
方法2:

使用ng更改

<input ng-change="checkValue()" ng-model="yourValue">
方法1:

绑定到输入元素:

<input ng-model="yourValue">
方法2:

使用ng更改

<input ng-change="checkValue()" ng-model="yourValue">

OliverJ90的答案应该有一个小小的改变。在html中执行此操作:

<form>
<!-- CODE -->
    <label>code</label>
    <input type="text" name="codeInput" placeholder="please insert your code..." ng-model="someValue" ng-change="myFunc()" >
    <!-- SUBMIT BUTTON -->
    <button type="submit" >Submit</button>
</form>
基本上,someValue变量将提供到输入框的双向数据绑定。也就是说,如果有人更改文本框中的值,则变量值将更改;如果有人更改变量值,则输入框值将更改。这就是我们使用ng模型的原因。ng change就像在change事件上调用函数一样,但这是由angular提供的


请注意,ng change Reuers ng model,如果没有它,它将无法工作。

对于OliverJ90的回答,应该有一个小的更改。在html中执行此操作:

<form>
<!-- CODE -->
    <label>code</label>
    <input type="text" name="codeInput" placeholder="please insert your code..." ng-model="someValue" ng-change="myFunc()" >
    <!-- SUBMIT BUTTON -->
    <button type="submit" >Submit</button>
</form>
基本上,someValue变量将提供到输入框的双向数据绑定。也就是说,如果有人更改文本框中的值,则变量值将更改;如果有人更改变量值,则输入框值将更改。这就是我们使用ng模型的原因。ng change就像在change事件上调用函数一样,但这是由angular提供的


请注意,ng change Reuers ng model,没有它将无法工作。

$scope。不建议使用$watch。我宁愿使用ngChange。$scope。$watch不推荐使用。我宁愿用零钱。
$scope.myFunc = function(){
    //Do the following if $scope.someValue.length >= 5
    $http({
        method  : 'POST',
        url     : 'offers.php',
        data    : $scope.someValue,  
        headers : { 'Content-Type': 'application/x-www-form-urlencoded' } 
    }).success(function(data) {
           //display the data somehow...
    });
}