Join the Stack Overflow Community
Stack Overflow is a community of 6.8 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I'm setting an attribute on my directive and I can access the value from within the controller but I can't access it within my angular.element which is in the controller:

controller: ['$scope', '$window', function($scope, $window) {
      console.log('my value is logged: ' + $scope.myvalue)
    angular.element($window).bind("scroll", function() {
      console.log('my value is not logged: ' + $scope.myvalue)
    }
}],  

I want to append elements to the dom only if $scope.myvalue is true and when a scroll point has been reached on the page.

How would I do this?

share|improve this question
    
The scroll event callback is outside of the angular digest cycle, have you tried wrapping the call to console.log using $scope.$apply? – mzulch Jan 23 '16 at 2:22
    
already modules around that have all this worked out for you – charlietfl Jan 23 '16 at 3:55
    
Have you tried angular.element($window).on() instead of .bind()? – Shaun Scovil Jan 23 '16 at 4:29
    
Got it sorted. $scope.$apply worked: $scope.$apply(function() { $scope.header; $scope.footer; }); – user1532669 Jan 23 '16 at 17:02
    
@mzulch if you want to answer the question I'll accept your $scope.$apply answer:) – user1532669 Jan 23 '16 at 17:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.