Search box in angular js

后端 未结 5 603
谎友^
谎友^ 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 09:50

    Found this to be a simplification of the accepted answer.

    // Directive
    app.directive('search', function () {
        return function ($scope, element) {
            element.bind("keyup", function (event) {
              var val = element.val();
              if(val.length > 2) {
                $scope.search(val);
              }
            });
        };
    });
    
    // In Controller
    $scope.search= function(val) {
      // fetch data
    }
    
    // HTML
    
    

提交回复
热议问题