I am trying to change top position of a DIV on Scroll event -
In controller i have-
angular.element($window).on("scroll", function(e) { vm.scrollTop = angular.element($window).scrollTop()+'px'; console.log(vm.scrollTop); });
In html -
<div ng-style="{'top': vm.scrollTop}"> Hello World </div>
On scroll event is printing scrollTop values in console but "Div" style never gets updated.
Please correct me if this is syntactically incorrect.
ng-style
take anexpression
not avalue
, try this<div ng-style="{'top': vm.scrollTop}">
$scope.$apply();
after settingvm.scrollTop
because the event handler is executing outside of angular's awareness.