angularJS scrolling not recognized in ng-view

杀马特。学长 韩版系。学妹 提交于 2019-12-12 04:32:38

问题


Does anyone know why this basic scroll directive doesn't work when I scroll in a template within ng-view? I know this is super vague but I can't find anything on the web. I have tried multiple variations of a scroll directive but none of them recognize scrolling within the template. I appreciate any help I can get. Thanks in advance!

I'm using this basic directive

directive("scroll", function ($window) {
    return function(scope, element, attrs) {
        angular.element($window).bind("scroll", function() {
            if (this.pageYOffset >= 100) {
                scope.boolChangeClass = true;
            } else {
                scope.boolChangeClass = false;
            }
        scope.$apply();
        });
    };
});

Here is the HTML

<ng-view><ng-view>

and a basic template for the view

<div scroll>
    <blah></blah>
</div>

I should also not that I am using the ngRoute to supply views to ng-view.


回答1:


I found the issue. Everything in my code was correct. The problem is that I had a piece of css that was hiding my overflow-x. Once I removed that the scroll event started firing.




回答2:


in my case

<div ng-view></div>

I used to use directive example

<input type="password" class="form-control" scroll="user.password" required>

directive

app.directive("scroll", function () {
    return {
    };
});


来源:https://stackoverflow.com/questions/41843098/angularjs-scrolling-not-recognized-in-ng-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!