-->

angularJS scrolling not recognized in ng-view

2019-09-10 02:35发布

问题:

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 {
    };
});