简体   繁体   English

停止AngularJS即时搜索

[英]Stop AngularJS Instant Search

I have built a simple search form in my AngularJS app, that as you type uses the built in filter magic of angular to filter a list of phones. 我在AngularJS应用程序中构建了一个简单的搜索表单,当您键入时使用内置的angular过滤器魔术来过滤电话列表。 I've wrapped mine in a form as when the user submits the form it ALSO does the filter, but creates a query string so you can navigate away from the list and return etc. 我已经将我的表单包装起来,就像用户提交表单时一样,它也进行过滤,但创建了查询字符串,因此您可以从列表中导航并返回等。

HTML: HTML:

<form class="form-search" ng-submit="$parent.queryChanged()">
        <div class="control-group">
                <label class="control-label" for="filter">Filter:</label>
                <div class="controls">
                        <input name="q" ng-model="$parent.query" id="filter" type="text">
                </div>
        </div>
</form>

JS: JS:

phonecatControllers.controller('PhoneListCtrl', ['$scope', 'Phone', '$location',
        function($scope, Phone, $location) {
                $scope.query = $location.search()['q'];
                $scope.queryChanged = function () {
                        $location.search('q', $scope.query)
                }
                $scope.phones = Phone.query();
                $scope.orderProp = 'age';
        }]);

What I want to do is disable the instant search, so the user ONLY submits the form and never gets the results on keyup alone. 我想做的是禁用即时搜索,因此用户仅提交表单,而永远不会仅在keyup上获得结果。 How do I do this? 我该怎么做呢?

Use 2 different variables for the ng-model of the input ( ng-model="$parent.query" ) and the parameter of the filter ( | filter:filterQuery ). 为输入的ng-model="$parent.query"ng-model="$parent.query" )和过滤器的参数( | filter:filterQuery )使用2个不同的变量。 This will make the input and the filter unrelated to each other. 这将使输入和过滤器互不相关。 Then when the form is submitted (in queryChanged ), update the filter parameter with the value of the ng-model ( $scope.filterQuery = $scope.query ). 然后,在提交表单时(在queryChanged ),使用ng-model的值( $scope.filterQuery = $scope.query )更新filter参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM