From 509dba73a67a4e2dcb1fb22106c7785efb48e6d1 Mon Sep 17 00:00:00 2001 From: Alek Storm Date: Fri, 15 Nov 2013 02:06:00 -0800 Subject: [PATCH 1/3] tmp --- src/select2.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/select2.js b/src/select2.js index ad387db..51bf66b 100644 --- a/src/select2.js +++ b/src/select2.js @@ -179,6 +179,13 @@ angular.module('ui.select2', []).value('uiSelect2Config', {}).directive('uiSelec }); } + if (attrs.uiSelect2) { + scope.$watch(attrs.uiSelect2, function (newVal, oldVal, scope) { + elm.select2(newVal); + controller.$render(); + }, true); + } + // Initialize the plugin late so that the injected DOM does not disrupt the template compiler $timeout(function () { elm.select2(opts); From 502fcd73c8bc654ad6b850c84a9b6338686a3098 Mon Sep 17 00:00:00 2001 From: changhiskhan Date: Mon, 3 Mar 2014 00:03:27 -0800 Subject: [PATCH 2/3] BUG: update opts when uiSelect2 attr value changes --- src/select2.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/select2.js b/src/select2.js index 51bf66b..df2869e 100644 --- a/src/select2.js +++ b/src/select2.js @@ -180,8 +180,9 @@ angular.module('ui.select2', []).value('uiSelect2Config', {}).directive('uiSelec } if (attrs.uiSelect2) { - scope.$watch(attrs.uiSelect2, function (newVal, oldVal, scope) { - elm.select2(newVal); + scope.$watch(attrs.uiSelect2, function (newVal) { + angular.extend(opts, newVal); + elm.select2(opts); controller.$render(); }, true); } From 76c7943d1c3376866e2bd53f3cedaf7c7370d24b Mon Sep 17 00:00:00 2001 From: changhiskhan Date: Wed, 5 Mar 2014 14:29:30 -0800 Subject: [PATCH 3/3] Cancel the initial rendering call if uiSelect2 watch was already triggered --- src/select2.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/select2.js b/src/select2.js index df2869e..0aef13b 100644 --- a/src/select2.js +++ b/src/select2.js @@ -179,8 +179,13 @@ angular.module('ui.select2', []).value('uiSelect2Config', {}).directive('uiSelec }); } + var initial_render; + if (attrs.uiSelect2) { scope.$watch(attrs.uiSelect2, function (newVal) { + if (initial_render !== undefined) { + $timeout.cancel(initial_render); + }; angular.extend(opts, newVal); elm.select2(opts); controller.$render(); @@ -188,7 +193,7 @@ angular.module('ui.select2', []).value('uiSelect2Config', {}).directive('uiSelec } // Initialize the plugin late so that the injected DOM does not disrupt the template compiler - $timeout(function () { + initial_render = $timeout(function () { elm.select2(opts); // Set initial value - I'm not sure about this but it seems to need to be there