From be1153e502a11a7076464c36d68d8c37afbb0152 Mon Sep 17 00:00:00 2001 From: Nick Horvath Date: Tue, 22 Mar 2016 11:55:43 -0400 Subject: [PATCH 1/5] add timeout before reflow add timeout to let things rerender before reflowing on ngModel change --- angular-floatThead.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/angular-floatThead.js b/angular-floatThead.js index a66db02..01b1348 100644 --- a/angular-floatThead.js +++ b/angular-floatThead.js @@ -45,7 +45,10 @@ if (ngModel) { // Set $watch to do a deep watch on the ngModel (collection) by specifying true as a 3rd parameter scope.$watch(attrs.ngModel, function () { - jQuery(element).floatThead('reflow'); + //give time for rerender before reflow + $timeout(function() { + jQuery(element).floatThead('reflow'); + }, 100); }, true); } else { $log.info('floatThead: ngModel not provided!'); From 5ee0224adac13c96579aaf1890158f387a7a3773 Mon Sep 17 00:00:00 2001 From: Nick Horvath Date: Tue, 22 Mar 2016 12:45:29 -0400 Subject: [PATCH 2/5] use ngModel.$formatters instead of a $watch $watch was not working correctly for me. I have switched it to use ngModel's $formatters which is more reliable. I also defaulted float-thead-enabled to true so you can leave it out if you don't need conditional enabling. --- angular-floatThead.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/angular-floatThead.js b/angular-floatThead.js index 01b1348..bc90c87 100644 --- a/angular-floatThead.js +++ b/angular-floatThead.js @@ -22,6 +22,12 @@ scope: { floatTheadEnabled: '=' }, + controller: function ($scope, $element, $attrs) { + // default float-thead-enabled to true if not present + if (!$attrs.hasOwnProperty('floatTheadEnabled')) { + $scope.floatTheadEnabled = $attrs.floatTheadEnabled = true; + } + }, link: link, restrict: 'A' }; @@ -43,13 +49,13 @@ }); if (ngModel) { - // Set $watch to do a deep watch on the ngModel (collection) by specifying true as a 3rd parameter - scope.$watch(attrs.ngModel, function () { - //give time for rerender before reflow + // hook the model $formatters to get notified when anything changes so we can reflow + ngModel.$formatters.push(function () { + // give time for rerender before reflow $timeout(function() { jQuery(element).floatThead('reflow'); - }, 100); - }, true); + }); + }); } else { $log.info('floatThead: ngModel not provided!'); } From 567c8d61bbde52e0463501cfb6c42c2796a9e05a Mon Sep 17 00:00:00 2001 From: Nick Horvath Date: Tue, 22 Mar 2016 12:45:59 -0400 Subject: [PATCH 3/5] forgot a ? forgot the ? in the scope definition for optional param --- angular-floatThead.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/angular-floatThead.js b/angular-floatThead.js index bc90c87..ccea85e 100644 --- a/angular-floatThead.js +++ b/angular-floatThead.js @@ -20,7 +20,7 @@ var directive = { require: '?ngModel', scope: { - floatTheadEnabled: '=' + floatTheadEnabled: '=?' }, controller: function ($scope, $element, $attrs) { // default float-thead-enabled to true if not present From 861596fdb5d38703450ab2717c03662c9e144416 Mon Sep 17 00:00:00 2001 From: Nick Horvath Date: Tue, 22 Mar 2016 12:49:39 -0400 Subject: [PATCH 4/5] allow floatThead 1.3.x I'm using 1.3.2 without issue. --- bower.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bower.json b/bower.json index 6980c86..4d4a872 100644 --- a/bower.json +++ b/bower.json @@ -25,6 +25,6 @@ "tests" ], "dependencies": { - "floatThead": "~1.2.8" + "floatThead": "^1.2.8" } } From 29667849bc5329e989b70f77ef8304e4b6ae5418 Mon Sep 17 00:00:00 2001 From: Nick Horvath Date: Tue, 22 Mar 2016 14:21:13 -0400 Subject: [PATCH 5/5] fix passing options to floatThead Options weren't properly being passed. Using scope.$eval meant that you couldn't use a bind to a parent scope object. For example: float-thead="floatTheadOptions" didn't work. By defining floatThead as an optional bind and just using scope.floatThead this is now possible and float-thead="{myOption: 123}" still works as well as omitting the options altogether. I also removed an extraneous check for isEnabled. the $watch will fire automatically on load with the initial value. --- angular-floatThead.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/angular-floatThead.js b/angular-floatThead.js index ccea85e..e2295db 100644 --- a/angular-floatThead.js +++ b/angular-floatThead.js @@ -20,6 +20,7 @@ var directive = { require: '?ngModel', scope: { + floatThead: '=?', floatTheadEnabled: '=?' }, controller: function ($scope, $element, $attrs) { @@ -36,13 +37,9 @@ function link(scope, element, attrs, ngModel) { var isEnabled = (scope.floatTheadEnabled === true); - if (isEnabled) { - jQuery(element).floatThead(scope.$eval(attrs.floatThead)); - } - scope.$watch('floatTheadEnabled', function (newVal) { if (newVal === true) { - jQuery(element).floatThead(scope.$eval(attrs.floatThead)); + jQuery(element).floatThead(scope.floatThead); } else { jQuery(element).floatThead('destroy'); }