繁体   English   中英

Bootstrap手风琴在Angular应用中打开或关闭时,如何运行某些代码?

[英]How can I run some code when a Bootstrap accordion opens or closes in my Angular app?

我正在使用Bootstrap和D3制作大部分视觉效果的Angular应用程序。 我从这里开始使用手风琴指令。 我想在手风琴组打开和关闭时触​​发D3图表中的更改。 我该如何抓住这个机会? 我在想我需要一种运行回调,更新模型或直接查询手风琴的方法。

我发现这个问题看起来似乎可以解决,但是由于这个问题太老了,我希望现在有一个更好的方法。

使用带有标志TRUE和FALSE的简单逻辑

<!doctype html>
<html ng-app="ui.bootstrap.demo">
<head>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular-animate.js"></script>
    <script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-1.3.3.js"></script>
    <link href="//netdna.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>

    <div ng-controller="AccordionDemoCtrl">
        <uib-accordion close-others="oneAtATime">
            <uib-accordion-group heading="Accordion-1" ng-click="call(is_open)">
                Accordion-1
            </uib-accordion-group>
            <uib-accordion-group heading="Accordion-2">
                Accordion-2
            </uib-accordion-group>
        </uib-accordion>
    </div>
</body>
</html>

<script type="text/javascript">
    angular.module('ui.bootstrap.demo', ['ngAnimate', 'ui.bootstrap']);
    angular.module('ui.bootstrap.demo').controller('AccordionDemoCtrl', function ($scope) 
    {
        $scope.is_open = false;
        $scope.call = function(status)
        {
            if(status==true)
            {
                $scope.is_open = false;
                console.log("close")
            }
            else
            {
                $scope.is_open = true;
                console.log("open")
            }
        }
    });
</script>

暂无
暂无

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

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