angular.js icon indicating copy to clipboard operation
angular.js copied to clipboard

ng-style doesn't work when window resize

Open buihoanghai opened this issue 12 years ago • 5 comments

ng-style can bind but it don't effect to style after resize window. In first binding

<div ng-style="{'left':'703px', 'top':'-11px'}" style="left: 703px; top: -11px;"></div>

after resize :

<div ng-repeat="com in vm.comments" ng-style="{'left':'525px', 'top':'-11px'}" style="left: 703px; top: -11px;"></div>

Data in ng-style is changed but style isn't.

buihoanghai avatar May 13 '14 09:05 buihoanghai

Can you provide the jsfiddle(http://jsfiddle.net/) URL for your bug to understand what u r changing on window resize.

sub2u avatar May 13 '14 09:05 sub2u

You must use $scope.$apply() when making changes in non-angular event handlers.

See https://code.angularjs.org/1.3.0-beta.7/docs/guide/scope, section "Integration with the browser event loop"

e: I see, this time the problem isn't applying the changes, it's the syntax.

Narretz avatar May 13 '14 10:05 Narretz

You can check it in: http://plnkr.co/edit/nCZKaveRLsahntPGjupY?p=preview Try resize window and compare data in ng-style vs style.

buihoanghai avatar May 13 '14 10:05 buihoanghai

Your ng-style syntax is not correct. Try this: ng-style="{'left': cam.left + 'px'}"

campersau avatar May 13 '14 12:05 campersau

Yes, it's right :+1: Thank you!

buihoanghai avatar May 14 '14 01:05 buihoanghai