Does .bind break $ scope in angularjs?

I am trying to bind a scroll for an image so that based on the scroll position I can change the value of $ scope. However, what I am doing is breaking value binding. Here's the JSFiddle:

http://jsfiddle.net/h2popz9t/

    $scope.testFun = function(a) {
        if (a.target.scrollLeft < 100) {
            $scope.something.yes = true;
        } else if (a.target.scrollLeft > 100) {
            $scope.something.yes = false;
        }
    };

    b.bind('scroll', $scope.testFun);

When "something.yes" changes (because you scrolled 100px), it should call "ng-show" in the div with the text "SOMETHING". Not this. Although, I know that they are connected initially, because something.yes has the correct value at startup.

I'm not sure how I messed up the binding to "$ scope.something"

+4
source share
3 answers

$scope, , . .

, :

function testFun(a) {
    $scope.$apply(function() {
        console.log("a", $scope.something);
        if (a.target.scrollLeft < 100) {
            $scope.something.yes = true;
        } else if (a.target.scrollLeft > 100) {
            $scope.something.yes = false;
        }
    });
}

b.bind('scroll', testFun);

http://jsfiddle.net/h2popz9t/5/

+2

bind on (, , ), $apply $scope . $apply $digest, , , $watchers, , - .

0

$scope.$apply() $scope.testFun, , , angular

  $scope.testFun = function(a) {
                console.log("a", $scope.something);
            if (a.target.scrollLeft < 100) {
                $scope.something.yes = true;
            } else if (a.target.scrollLeft > 100) {
                $scope.something.yes = false;
            }
            $scope.$apply();
        };

fiddle

0