Disabling orderBy in AngularJS while editing the list

前端 未结 8 694
情歌与酒
情歌与酒 2021-01-07 23:06

After applying orderBy in my list of input boxes if i edit any field it starts sorting immediately and i loose focus. I tried to dug in the angular code and fou

8条回答
  •  南方客
    南方客 (楼主)
    2021-01-07 23:45

    A different approach may be to not loose focus to begin with. If your main problem is that your loosing focus, then instead of disabling orderBy, add this directive to your input:

    app.directive("keepFocus", ['$timeout', function ($timeout) {
        /*
        Intended use:
            
        */
        return {
            restrict: 'A',
            require: 'ngModel',
            link: function ($scope, $element, attrs, ngModel) {
    
                ngModel.$parsers.unshift(function (value) {
                    $timeout(function () {
                        $element[0].focus();
                    });
                    return value;
                });
    
            }
        };
    }])
    

    Then just:

    
    

    I know this does not directly answer you question, but it might help solve the underlying problem.

提交回复
热议问题