1

I am working on a AngularJs based SPA. Search box has a autocomplete function which is not working properly. When I start typing in the search box, typed string appears in {{search.name}} and suggestion come in but when I click on one of the suggestion it doesn't appear in {{search.name}}.After that if any other button is pressed string appears.

This is my html code

<div class=" upper-one">

      <div class="search-box" style="display:inline;">
        <img src="img/search.png" width="28px" height="28px" style="float:left;">
        <input id="tags" class="input-search-box" type="text" placeholder="Start typing " data-ng-model="search.name"></input>
     <a>   <div class="go-class" style="position:relative;" data-ng-click="searchProduct()"> Go</div> </a>
      </div>

      {{search.name}  
</div>

This is my jquery code

<script >
  $(function() {
  var availableTags =["Jquery","Html","Css"
];
  $( "#tags" ).autocomplete({
  source: availableTags
  });
 });
</script>  

What is wrong with my code?

1 Answer 1

1

This can be solved by simply using the Angular autocomplete.

  function DefaultCtrl($scope) {
$scope.names = ["john", "bill", "charlie", "robert", "alban", "oscar", "marie", "celine", "brad", "drew", "rebecca", "michel", "francis", "jean", "paul", "pierre", "nicolas", "alfred", "gerard", "louis", "albert", "edouard", "benoit", "guillaume", "nicolas", "joseph"];}

angular.module('MyModule', []).directive('autoComplete', function($timeout) {
return function(scope, iElement, iAttrs) {
        iElement.autocomplete({
            source: scope[iAttrs.uiItems],
            select: function() {
                $timeout(function() {
                  iElement.trigger('input');
                }, 0);
            }
        });
}; 
 });




  <div ng-app='MyModule'>
<div ng-controller='DefaultCtrl'>
    <input auto-complete ui-items="names" ng-model="selected">
    selected = {{selected}}
</div>

Reference: http://jsfiddle.net/sebmade/swfjT/light/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.