Angular 滑块指令不起作用

Angular slider directive does not working

我想将此指令添加到我的网站:angular-slider

问题是无法正常工作。这是代码:

查看:

        ....
        <div class="col-sm-12 col-md-3 toggle-slide landing-square" ng-click="open_question = !open_question">
        <div class="inner-content">
        </div>
    </div>
</div>
<div class="row toggle-slide">
    <div class="black-line col-xs-12" ng-show="!scrolled">
        <div class="black-box"></div>
    </div>
    <div slider="open_question" class='col-xs-12 three-questions slideable-content'>
    </div>
</div>
....

控制器:

use 'strict';

angular.module('myApp.landing', ['ngRoute'])

.config(['$routeProvider', function($routeProvider) {
}])
.controller('landingCtrl', ["$scope", "$http", "URL",  function($scope, $http, URL) {
    $scope.scrolled = false;
    $scope.open_question = false;
}]).
directive("scroll", ["$window", function($window){
    return {
        scope: false,
        link: function($scope, element, attrs){
            angular.element($window).bind("scroll", function(){
                if (this.pageYOffset >= 1000) {
                     $scope.scrolled = true;
                     var body_el = angular.element(document.querySelector(".toggle-slide"));
                     angular.element(body_el).triggerHandler('click');
                } else {
                    $scope.scrolled = false;
                }
                $scope.$apply();
            });
        }
    };
}])
.directive('slider', function () {
    return {
        restrict:'A',
        compile: function (element) {
            // wrap tag
            var contents = element.html();
            element.html('<div class="slideable_content" style=" margin:0 !important; padding:0 !important" >' + contents + '</div>');

            return function postLink(scope, element, attrs) {
                var i = 0;
                // default properties
                scope.$watch(attrs.slider, (n, o) => {
                    if (n !== o) {
                        i++;
                        var target = element[0],
                            content = target.querySelector('.slideable_content');
                        if(n) {
                            content.style.border = '1px solid rgba(0,0,0,0)';
                            var y = content.clientHeight, z = i;
                            content.style.border = 0;
                            target.style.height = y + 'px';
                            setTimeout(() => {
                                if (z === i) {
                                    target.style.height = 'auto';
                                }
                            }, 500);
                        } else {
                            target.style.height = target.clientHeight + 'px';
                            setTimeout(() => {
                                target.style.height = '0px';
                            });
                        }
                    }
                });

                attrs.duration = (!attrs.duration) ? '0.5s' : attrs.duration;
                attrs.easing = (!attrs.easing) ? 'ease-in-out' : attrs.easing;
                element.css({
                    'overflow': 'hidden',
                    'height': '0px',
                    'transitionProperty': 'height',
                    'transitionDuration': attrs.duration,
                    'transitionTimingFunction': attrs.easing
                });
            };
        }
    };
});

我首先尝试通过单击 div(如 js fiddle)触发幻灯片,但它不起作用。另外,我想让它在页面到达某个滚动条时发生(这也是我添加滚动指令的原因)。我错过了什么?控制台完全没有显示错误...

好的,原来如果我没有内容,隐藏的高度 div 是 0,所以触发器没有什么可显示的!

如果我在 div 中添加一些 <br> 标签,它会很好地工作:

<div slider="open_question" class='col-xs-12 three-questions slideable-content'>
    <br>
    <br>
    <br>
</div>

剩下的唯一问题是,如果不实际单击另一个 div,我仍然无法使它工作。

编辑:好的,我的错,它与滚动指令触发的点击一起工作,我只是拼错了变量名! 这就是我必须在滚动指令中添加的全部内容:

 $scope.open_question = true;