Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 如何从引导按钮中删除:活动_Angularjs_Twitter Bootstrap - Fatal编程技术网

Angularjs 如何从引导按钮中删除:活动

Angularjs 如何从引导按钮中删除:活动,angularjs,twitter-bootstrap,Angularjs,Twitter Bootstrap,我有一个网站,我有多个按钮。一旦按下一个按钮,我就会填充一个列表,尽管我的问题是最后按下的按钮看起来一直被按下(具有:active类)。我考虑过使用angular的$timeout来重置按钮,尽管removeClass函数不能实现这一点 我的观点是这样的: div(ng-controller='productButtonController') div(ng-repeat='product in products') div.col-md-4

我有一个网站,我有多个按钮。一旦按下一个按钮,我就会填充一个列表,尽管我的问题是最后按下的按钮看起来一直被按下(具有
:active
类)。我考虑过使用angular的
$timeout
来重置按钮,尽管
removeClass
函数不能实现这一点

我的观点是这样的:

    div(ng-controller='productButtonController')
    div(ng-repeat='product in products')
        div.col-md-4
            button.btn.btn-block.sell-button(id='{{product._id}}' ng-click='sell()'){{product.name}}
和我的控制器:

app.controller('productButtonController', ['$scope', '$timeout', 'productServices', 'flash',
    function($scope, $timeout, productServices, flash) {
        productServices.getProducts()
            .success(function(result) {
                $scope.products = result.data
            })
            .error(showErrorMessage(flash))

        $scope.sell = function() {
            console.log(this.product)
            that = this
            $('#' + that.product._id).removeClass('active')
        }
    }
])

如果您只是想覆盖引导按钮的焦点状态,您可以使用:

.btn:focus{
    outline: none;
}
然后,您的按钮应该如下所示:

<button class="btn btn-default">My button 1</button>
让我知道这是否适合你

  • 将angular$window服务添加到 控制器
  • 对文档的活动元素调用blur方法,该元素将 你的按钮
  • $window.document.activeElement.blur()


    请参阅。

    贾斯汀·波内特的这段代码优雅地解决了这个问题

    app.directive('blur', [function () {
        return {
            restrict: 'A',
            link: function (scope, element) {
                element.on('click', function () {
                    element.blur();
                });
            }
        };
    }]);
    
    将模糊属性添加到单击后需要模糊的按钮/元素。例如

    <button type="button" blur>Click me</button>
    
    点击我
    
    按钮的代码是什么样子的?我遇到了一个问题,我使用bootstraps toggle同时更改了外观和angulars样式的条件,这导致按钮被双重切换,因此无法正确显示。请显示您的js/html代码。如果可能的话,复制这把小提琴。这是最有效的,因为你可以在你的应用程序中的任何需要的地方使用它。很好的解决方案。必须更改为
    元素[0].blur()使其工作。
    
    <button type="button" blur>Click me</button>