Merge pull request #2253 from coreos-inc/BUG-angular-apply-error
fix(js/onresize): make sync call async in angular
This commit is contained in:
commit
72191bbd37
1 changed files with 9 additions and 5 deletions
|
@ -1,14 +1,18 @@
|
||||||
/**
|
/**
|
||||||
* Adds an onresize event attribtue that gets invokved when the size of the window changes.
|
* Adds an onresize event attribute that gets invokved when the size of the window changes.
|
||||||
*/
|
*/
|
||||||
angular.module('quay').directive('onresize', function ($window, $parse) {
|
angular.module('quay').directive('onresize', function ($window, $parse, $timeout) {
|
||||||
return function (scope, element, attr) {
|
return function (scope, element, attr) {
|
||||||
var fn = $parse(attr.onresize);
|
var fn = $parse(attr.onresize);
|
||||||
|
|
||||||
var notifyResized = function() {
|
var notifyResized = function() {
|
||||||
scope.$apply(function () {
|
// Angular.js enforces only one call to $apply can run at a time.
|
||||||
|
// Use $timeout to make the scope update safe, even when called within another $apply block,
|
||||||
|
// by scheduling it on the call stack.
|
||||||
|
// See docs: https://docs.angularjs.org/error/$rootScope/inprog
|
||||||
|
$timeout(function () {
|
||||||
fn(scope);
|
fn(scope);
|
||||||
});
|
}, 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
angular.element($window).on('resize', null, notifyResized);
|
angular.element($window).on('resize', null, notifyResized);
|
||||||
|
|
Reference in a new issue