AngularJS ng-click按钮事件导致页面滚动到按钮

时间:2020-01-27 13:13:07

标签: angularjs button angularjs-ng-click

$ scope.Decrement =函数(x){

        debugger;

        var res1 = kid.substring(4);
        myobject = { Username: '8892696780', MenuId: x, KitchenId: res1, OrderId: '0125', VarientId: null, Increment: null, Decrement: 1 }

        Object.toparams = function ObjecttoParams(obj) {
            var p = [];
            for (var key in obj) {
                p.push(key + '=' + encodeURIComponent(obj[key]));
            }
            return p.join('&');
        };

        $http({
            method: 'POST',
            url: '../api/AddToCart',
            data: Object.toparams(myobject),
            headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
        }).then(function successCallback(response) {
            $scope.GetMenuItems();
            $scope.GetCartItems();

            }, function errorCallback(response) {



            alert("Error. while updating user Try Again!");

        });
    };

<div ng-hide="a.ButtonStatus == null"> <span class="float-right"> <span class="count-number"> <a id="btnDecrement" ng-click="Decrement(a.MenuId)" class="btn btn-outline-secondary btn-sm left dec"> <i class="icofont-minus"></i> </a> <input class="count-number-input" type="text" value="{{a.ButtonStatus}}" readonly=""> <a id="btnIncrement" ng-click="Increment(a.MenuId)" class="btn btn-outline-secondary btn-sm right inc"> <i class="icofont-plus"></i> </a> </span> </span> </div>

如何避免单击按钮后页面向下滚动?我尝试了很多$ event.preventDefaul();也。

0 个答案:

没有答案
相关问题