javascript - tracking user input and offer word completion- angular -


i new in angular , need help. lets have db contains list of numbers , want use list word completion.

assume form:

          <!-- form -->           <form>                  <!-- code -->                   <label>code</label>                   <input type="text" name="codeinput" placeholder="please insert code..." >                  <!-- submit button -->                 <button type="submit" >submit                 </button>          </form> 

upon user inserts @ least 5 chars want make ajax call offers.php retrieve offers , display them.

note ajax call before submitting form

the php code working... stuck on client side.

i know should like:

                            $http({                         method  : 'post',                         url     : 'offers.php',                         data    : $.param(code),                           headers : { 'content-type': 'application/x-www-form-urlencoded' }                          })                         .success(function(data)                            {                             //display data somehow...                          }); 

i can't figure out how connect components.

on oliverj90's answer there should small change. in html:

<form> <!-- code -->     <label>code</label>     <input type="text" name="codeinput" placeholder="please insert code..." ng-model="somevalue" ng-change="myfunc()" >     <!-- submit button -->     <button type="submit" >submit</button> </form> 

and javascript this

$scope.myfunc = function(){     //do 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 data somehow...     }); } 

basically somevalue variable provide 2 way data-binding input box. is, if changes value in text box, variable value change, , if changes variable value, input box value change. reason have used ng-model. ng-change calling function on change event, provided angular.

please note that, ng-change reuires ng-model, without not work.


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -