Search box in angular js

后端 未结 5 607
谎友^
谎友^ 2021-01-30 09:09

I want to implement a search box in my angularJs application. As soon as user starts typing some name in the search box , some REST service should be called and it should fetch

5条回答
  •  星月不相逢
    2021-01-30 10:09

    Why so much drama, directives, and Glyptodon blood?

    Since angular already has

    ng-keypress
    ng-keyup
    ng-keydown
    

    Use any of those to invoke REST service just as you would with ng-click.

    HTML

    
    

    JS

    vm.search = search;
    
    function search() {
      // Call your cool REST service and attach data to it
      vm.data = MyCoolService.myGetFunctionWhatever();
      // You can use vm.query ng-model to limit search after 2 input values for example
      //     if(vm.query.length > 2) do your magic
    };
    

提交回复
热议问题