From 9408de3f17933a7bec36728b10b8eabaca440aab Mon Sep 17 00:00:00 2001 From: Victor Didenko Date: Wed, 29 Nov 2017 16:32:12 +0300 Subject: [PATCH 1/2] Add arrays support for deferred chips --- dist/angular-chips.js | 26 ++++++++++++++++++++------ dist/angular-chips.min.js | 2 +- src/js/directives/chips.js | 26 ++++++++++++++++++++------ 3 files changed, 41 insertions(+), 13 deletions(-) diff --git a/dist/angular-chips.js b/dist/angular-chips.js index 0b3847f..f8d7dc9 100644 --- a/dist/angular-chips.js +++ b/dist/angular-chips.js @@ -9,6 +9,10 @@ return obj && angular.isFunction(obj.then); } + function isArray(obj) { + return Object.prototype.toString.call(obj) === '[object Array]'; + } + /* * update values to ngModel reference */ @@ -106,13 +110,20 @@ } else { updatedData = data } if (!updatedData) { - return false; + return false; } if (isPromiseLike(updatedData)) { - updatedData.then(function(response) { - model.add(response); - }); + updatedData = updatedData.then(function(response) { + if (response == null || (isArray(response) && !response.length)) { + throw data; // got no data + } + var arr = isArray(response) ? response : [response]; + var first = arr.shift(); // get first element, it will be populated to DeferChip + update(arr.map(function(r) { return { defer: r } })); // add all other elements, if any + model.add(first); + return first; + }) scope.chips.list.push(new DeferChip(data, updatedData)); scope.$apply(); } else { @@ -120,8 +131,11 @@ } function update(data) { - scope.chips.list.push(data); - model.add(data); + var arr = isArray(data) ? data : [data]; + for (var i = 0; i < arr.length; i++) { + scope.chips.list.push(arr[i]); + model.add(arr[i]); + } } return true; diff --git a/dist/angular-chips.min.js b/dist/angular-chips.min.js index 0d7fdb1..7726105 100644 --- a/dist/angular-chips.min.js +++ b/dist/angular-chips.min.js @@ -1 +1 @@ -!function(){function e(e){return e&&angular.isFunction(e.then)}function n(e){return{add:function(n){var t=angular.copy(e.$modelValue)||[];t.push(n),e.$setViewValue(t)},"delete":function(n){var t=angular.copy(e.$modelValue);t.splice(n,1),e.$setViewValue(t)},deleteByValue:function(n){var t,i;for(t=0;tl.chips.list.length-1?0:e}}if(""!==(error=o(a)))throw error;var f=n(s),h=u.hasOwnProperty("defer"),m=i(u.render);l.chips.list,l.chips.addChip=function(n){function i(e){l.chips.list.push(e),f.add(e)}var r,o;return void 0!==l.render&&""!==m?(o={},o[m]=n,r=l.render(o)):r=n,!!r&&(e(r)?(r.then(function(e){f.add(e)}),l.chips.list.push(new t(n,r)),l.$apply()):i(r),!0)},l.chips.deleteChip=function(e){var n=l.chips.list.splice(e,1)[0];return n.isFailed?void l.$apply():void(n instanceof t?f.deleteByValue(n.defer):f["delete"](e))},s.$render=function(){if(h&&s.$modelValue){var e,n=[];for(e=0;e"),C=a.html();C=C.substr(C.indexOf("")-"".length),a.find("chip-tmpl").remove();var $=angular.element(C);$.attr("ng-repeat","chip in chips.list track by $index"),$.attr("ng-class","{'chip-failed':chip.isFailed}"),$.attr("tabindex","-1"),$.attr("index","{{$index+1}}"),g.append($);var y=r(g)(l);a.prepend(y),a.on("click",function(e){"CHIPS"===e.target.nodeName&&a.find("input")[0].focus()}),a.find("input").on("focus",function(){v=null}),l.chips.handleKeyDown=function(e){function n(){var n=parseInt(document.activeElement.getAttribute("index"))||(t=a.find("chip-tmpl")).length;t=a.find("chip-tmpl"),t[n-1].focus(),v=p(n-1),"INPUT"!==e.target.nodeName&&t[v(e.keyCode)].focus()}if(!("INPUT"!==e.target.nodeName&&"CHIP-TMPL"!==e.target.nodeName||0===a.find("chip-tmpl").length&&""===e.target.value)){var t;if(8===e.keyCode){if("INPUT"===e.target.nodeName&&""===e.target.value)n(),e.preventDefault();else if("CHIP-TMPL"===e.target.nodeName){var i=a.find("chip-tmpl");i.length>0&&parseInt(e.target.getAttribute("index"))-1===i.length&&a.find("chip-tmpl")[v(37)].focus()}}else 37!==e.keyCode&&39!==e.keyCode||(null===v?n():a.find("chip-tmpl")[v(e.keyCode)].focus())}},a.on("keydown",l.chips.handleKeyDown),c(a).addClass("chip-out-focus")}return a.$inject=["scope","iElement","iAttrs","ngModelCtrl","transcludefn"],{restrict:"E",scope:{render:"&?"},transclude:!0,require:"ngModel",link:a,controller:"chipsController",controllerAs:"chips",template:"
"}}function o(e){return 0===e.find("chip-tmpl").length?"should have chip-tmpl":e.find("chip-tmpl").length>1?"should have only one chip-tmpl":""}function l(e,n,t){this.setFocus=function(e){e?t(n).removeClass("chip-out-focus").addClass("chip-in-focus"):t(n).removeClass("chip-in-focus").addClass("chip-out-focus")},this.removeChip=function(e,n){this.deleteChip(n)}}r.$inject=["$compile","$timeout","DomUtil"],l.$inject=["$scope","$element","DomUtil"],angular.module("angular.chips",[]).directive("chips",r).controller("chipsController",l)}(),function(){function e(){return{restrict:"E",transclude:!0,link:function(e,n,t,i,r){r(e,function(e){n.append(e)}),n.on("keydown",function(n){8===n.keyCode&&(e.$broadcast("chip:delete"),n.preventDefault())})}}}angular.module("angular.chips").directive("chipTmpl",e)}(),function(){function e(){return{restrict:"A",require:"^?chips",link:function(e,n,t,i){function r(e,n){var t;if(n.search("\\(")>0&&(n=n.substr(0,n.search("\\("))),void 0!==n)if(n.split(".").length>1){var i=n.split(".");t=e;for(var r=0;rc.chips.list.length-1?0:e}}if(""!==(error=l(a)))throw error;var h=t(d),m=s.hasOwnProperty("defer"),v=r(s.render);c.chips.list,c.chips.addChip=function(t){function r(e){for(var t=n(e)?e:[e],i=0;i"),$=a.html();$=$.substr($.indexOf("")-"".length),a.find("chip-tmpl").remove();var y=angular.element($);y.attr("ng-repeat","chip in chips.list track by $index"),y.attr("ng-class","{'chip-failed':chip.isFailed}"),y.attr("tabindex","-1"),y.attr("index","{{$index+1}}"),C.append(y);var k=o(C)(c);a.prepend(k),a.on("click",function(e){"CHIPS"===e.target.nodeName&&a.find("input")[0].focus()}),a.find("input").on("focus",function(){g=null}),c.chips.handleKeyDown=function(e){function n(){var n=parseInt(document.activeElement.getAttribute("index"))||(t=a.find("chip-tmpl")).length;t=a.find("chip-tmpl"),t[n-1].focus(),g=f(n-1),"INPUT"!==e.target.nodeName&&t[g(e.keyCode)].focus()}if(!("INPUT"!==e.target.nodeName&&"CHIP-TMPL"!==e.target.nodeName||0===a.find("chip-tmpl").length&&""===e.target.value)){var t;if(8===e.keyCode){if("INPUT"===e.target.nodeName&&""===e.target.value)n(),e.preventDefault();else if("CHIP-TMPL"===e.target.nodeName){var i=a.find("chip-tmpl");i.length>0&&parseInt(e.target.getAttribute("index"))-1===i.length&&a.find("chip-tmpl")[g(37)].focus()}}else 37!==e.keyCode&&39!==e.keyCode||(null===g?n():a.find("chip-tmpl")[g(e.keyCode)].focus())}},a.on("keydown",c.chips.handleKeyDown),u(a).addClass("chip-out-focus")}return a.$inject=["scope","iElement","iAttrs","ngModelCtrl","transcludefn"],{restrict:"E",scope:{render:"&?"},transclude:!0,require:"ngModel",link:a,controller:"chipsController",controllerAs:"chips",template:"
"}}function l(e){return 0===e.find("chip-tmpl").length?"should have chip-tmpl":e.find("chip-tmpl").length>1?"should have only one chip-tmpl":""}function c(e,n,t){this.setFocus=function(e){e?t(n).removeClass("chip-out-focus").addClass("chip-in-focus"):t(n).removeClass("chip-in-focus").addClass("chip-out-focus")},this.removeChip=function(e,n){this.deleteChip(n)}}o.$inject=["$compile","$timeout","DomUtil"],c.$inject=["$scope","$element","DomUtil"],angular.module("angular.chips",[]).directive("chips",o).controller("chipsController",c)}(),function(){function e(){return{restrict:"E",transclude:!0,link:function(e,n,t,i,r){r(e,function(e){n.append(e)}),n.on("keydown",function(n){8===n.keyCode&&(e.$broadcast("chip:delete"),n.preventDefault())})}}}angular.module("angular.chips").directive("chipTmpl",e)}(),function(){function e(){return{restrict:"A",require:"^?chips",link:function(e,n,t,i){function r(e,n){var t;if(n.search("\\(")>0&&(n=n.substr(0,n.search("\\("))),void 0!==n)if(n.split(".").length>1){var i=n.split(".");t=e;for(var r=0;r Date: Wed, 29 Nov 2017 18:28:37 +0300 Subject: [PATCH 2/2] Add example for arrays / Fixed chips deletion --- dist/angular-chips.js | 10 ++-- dist/angular-chips.min.js | 2 +- samples/index.html | 26 +++++++++ samples/using_promise_str_array_example.js | 65 ++++++++++++++++++++++ src/js/directives/chips.js | 8 +-- 5 files changed, 101 insertions(+), 10 deletions(-) create mode 100644 samples/using_promise_str_array_example.js diff --git a/dist/angular-chips.js b/dist/angular-chips.js index f8d7dc9..f3acf28 100644 --- a/dist/angular-chips.js +++ b/dist/angular-chips.js @@ -1,5 +1,5 @@ (function() { - Chips.$inject = ["$compile", "$timeout", "DomUtil"]; + Chips.$inject = ["$q", "$compile", "$timeout", "DomUtil"]; ChipsController.$inject = ["$scope", "$element", "DomUtil"]; angular.module('angular.chips', []) .directive('chips', Chips) @@ -77,7 +77,7 @@ return funStr.substr(openParenthesisIndex, closeParenthesisIndex - openParenthesisIndex); } /*@ngInject*/ - function Chips($compile, $timeout, DomUtil) { + function Chips($q, $compile, $timeout, DomUtil) { /*@ngInject*/ linkFun.$inject = ["scope", "iElement", "iAttrs", "ngModelCtrl", "transcludefn"]; function linkFun(scope, iElement, iAttrs, ngModelCtrl, transcludefn) { @@ -120,7 +120,7 @@ } var arr = isArray(response) ? response : [response]; var first = arr.shift(); // get first element, it will be populated to DeferChip - update(arr.map(function(r) { return { defer: r } })); // add all other elements, if any + update(arr, true); // add all other elements, if any model.add(first); return first; }) @@ -130,10 +130,10 @@ update(updatedData); } - function update(data) { + function update(data, defer) { var arr = isArray(data) ? data : [data]; for (var i = 0; i < arr.length; i++) { - scope.chips.list.push(arr[i]); + scope.chips.list.push(defer ? new DeferChip(arr[i], $q.when(arr[i])) : arr[i]); model.add(arr[i]); } } diff --git a/dist/angular-chips.min.js b/dist/angular-chips.min.js index 7726105..8522ea0 100644 --- a/dist/angular-chips.min.js +++ b/dist/angular-chips.min.js @@ -1 +1 @@ -!function(){function e(e){return e&&angular.isFunction(e.then)}function n(e){return"[object Array]"===Object.prototype.toString.call(e)}function t(e){return{add:function(n){var t=angular.copy(e.$modelValue)||[];t.push(n),e.$setViewValue(t)},"delete":function(n){var t=angular.copy(e.$modelValue);t.splice(n,1),e.$setViewValue(t)},deleteByValue:function(n){var t,i;for(t=0;tc.chips.list.length-1?0:e}}if(""!==(error=l(a)))throw error;var h=t(d),m=s.hasOwnProperty("defer"),v=r(s.render);c.chips.list,c.chips.addChip=function(t){function r(e){for(var t=n(e)?e:[e],i=0;i"),$=a.html();$=$.substr($.indexOf("")-"".length),a.find("chip-tmpl").remove();var y=angular.element($);y.attr("ng-repeat","chip in chips.list track by $index"),y.attr("ng-class","{'chip-failed':chip.isFailed}"),y.attr("tabindex","-1"),y.attr("index","{{$index+1}}"),C.append(y);var k=o(C)(c);a.prepend(k),a.on("click",function(e){"CHIPS"===e.target.nodeName&&a.find("input")[0].focus()}),a.find("input").on("focus",function(){g=null}),c.chips.handleKeyDown=function(e){function n(){var n=parseInt(document.activeElement.getAttribute("index"))||(t=a.find("chip-tmpl")).length;t=a.find("chip-tmpl"),t[n-1].focus(),g=f(n-1),"INPUT"!==e.target.nodeName&&t[g(e.keyCode)].focus()}if(!("INPUT"!==e.target.nodeName&&"CHIP-TMPL"!==e.target.nodeName||0===a.find("chip-tmpl").length&&""===e.target.value)){var t;if(8===e.keyCode){if("INPUT"===e.target.nodeName&&""===e.target.value)n(),e.preventDefault();else if("CHIP-TMPL"===e.target.nodeName){var i=a.find("chip-tmpl");i.length>0&&parseInt(e.target.getAttribute("index"))-1===i.length&&a.find("chip-tmpl")[g(37)].focus()}}else 37!==e.keyCode&&39!==e.keyCode||(null===g?n():a.find("chip-tmpl")[g(e.keyCode)].focus())}},a.on("keydown",c.chips.handleKeyDown),u(a).addClass("chip-out-focus")}return a.$inject=["scope","iElement","iAttrs","ngModelCtrl","transcludefn"],{restrict:"E",scope:{render:"&?"},transclude:!0,require:"ngModel",link:a,controller:"chipsController",controllerAs:"chips",template:"
"}}function l(e){return 0===e.find("chip-tmpl").length?"should have chip-tmpl":e.find("chip-tmpl").length>1?"should have only one chip-tmpl":""}function c(e,n,t){this.setFocus=function(e){e?t(n).removeClass("chip-out-focus").addClass("chip-in-focus"):t(n).removeClass("chip-in-focus").addClass("chip-out-focus")},this.removeChip=function(e,n){this.deleteChip(n)}}o.$inject=["$compile","$timeout","DomUtil"],c.$inject=["$scope","$element","DomUtil"],angular.module("angular.chips",[]).directive("chips",o).controller("chipsController",c)}(),function(){function e(){return{restrict:"E",transclude:!0,link:function(e,n,t,i,r){r(e,function(e){n.append(e)}),n.on("keydown",function(n){8===n.keyCode&&(e.$broadcast("chip:delete"),n.preventDefault())})}}}angular.module("angular.chips").directive("chipTmpl",e)}(),function(){function e(){return{restrict:"A",require:"^?chips",link:function(e,n,t,i){function r(e,n){var t;if(n.search("\\(")>0&&(n=n.substr(0,n.search("\\("))),void 0!==n)if(n.split(".").length>1){var i=n.split(".");t=e;for(var r=0;ra.chips.list.length-1?0:e}}if(""!==(error=l(s)))throw error;var v=t(p),m=d.hasOwnProperty("defer"),g=r(d.render);a.chips.list,a.chips.addChip=function(t){function r(e,t){for(var r=n(e)?e:[e],l=0;l"),y=s.html();y=y.substr(y.indexOf("")-"".length),s.find("chip-tmpl").remove();var k=angular.element(y);k.attr("ng-repeat","chip in chips.list track by $index"),k.attr("ng-class","{'chip-failed':chip.isFailed}"),k.attr("tabindex","-1"),k.attr("index","{{$index+1}}"),$.append(k);var V=c($)(a);s.prepend(V),s.on("click",function(e){"CHIPS"===e.target.nodeName&&s.find("input")[0].focus()}),s.find("input").on("focus",function(){C=null}),a.chips.handleKeyDown=function(e){function n(){var n=parseInt(document.activeElement.getAttribute("index"))||(t=s.find("chip-tmpl")).length;t=s.find("chip-tmpl"),t[n-1].focus(),C=h(n-1),"INPUT"!==e.target.nodeName&&t[C(e.keyCode)].focus()}if(!("INPUT"!==e.target.nodeName&&"CHIP-TMPL"!==e.target.nodeName||0===s.find("chip-tmpl").length&&""===e.target.value)){var t;if(8===e.keyCode){if("INPUT"===e.target.nodeName&&""===e.target.value)n(),e.preventDefault();else if("CHIP-TMPL"===e.target.nodeName){var i=s.find("chip-tmpl");i.length>0&&parseInt(e.target.getAttribute("index"))-1===i.length&&s.find("chip-tmpl")[C(37)].focus()}}else 37!==e.keyCode&&39!==e.keyCode||(null===C?n():s.find("chip-tmpl")[C(e.keyCode)].focus())}},s.on("keydown",a.chips.handleKeyDown),u(s).addClass("chip-out-focus")}return s.$inject=["scope","iElement","iAttrs","ngModelCtrl","transcludefn"],{restrict:"E",scope:{render:"&?"},transclude:!0,require:"ngModel",link:s,controller:"chipsController",controllerAs:"chips",template:"
"}}function l(e){return 0===e.find("chip-tmpl").length?"should have chip-tmpl":e.find("chip-tmpl").length>1?"should have only one chip-tmpl":""}function c(e,n,t){this.setFocus=function(e){e?t(n).removeClass("chip-out-focus").addClass("chip-in-focus"):t(n).removeClass("chip-in-focus").addClass("chip-out-focus")},this.removeChip=function(e,n){this.deleteChip(n)}}o.$inject=["$q","$compile","$timeout","DomUtil"],c.$inject=["$scope","$element","DomUtil"],angular.module("angular.chips",[]).directive("chips",o).controller("chipsController",c)}(),function(){function e(){return{restrict:"E",transclude:!0,link:function(e,n,t,i,r){r(e,function(e){n.append(e)}),n.on("keydown",function(n){8===n.keyCode&&(e.$broadcast("chip:delete"),n.preventDefault())})}}}angular.module("angular.chips").directive("chipTmpl",e)}(),function(){function e(){return{restrict:"A",require:"^?chips",link:function(e,n,t,i){function r(e,n){var t;if(n.search("\\(")>0&&(n=n.substr(0,n.search("\\("))),void 0!==n)if(n.split(".").length>1){var i=n.split(".");t=e;for(var r=0;rUsing Promise (with list of string)
usingPromise.list = {{usingPromise.list}}
+ + + +
+

Using Promise, returning array (with list of string)

+
For example, type "korea" to get both Koreas at once!
+
+ + +
+ {{chip.defer}} + +
+ +
+
+
+ +
+ +
+ Controller: +
usingPromise.list = {{usingPromise.list}}
+
+
@@ -134,6 +159,7 @@

Using bootstrap.ui.typeahead

+ diff --git a/samples/using_promise_str_array_example.js b/samples/using_promise_str_array_example.js new file mode 100644 index 0000000..3ac006f --- /dev/null +++ b/samples/using_promise_str_array_example.js @@ -0,0 +1,65 @@ +(function() { + angular.module('sample') + .controller('usingPromiseStrArrayController', UsingPromiseStrArrayController); + + function UsingPromiseStrArrayController($scope, $q) { + var self = this; + + var countries = [ + 'Afghanistan','Albania','Algeria','Andorra','Angola','Anguilla','Antigua & Barbuda','Argentina','Armenia','Australia','Austria','Azerbaijan', + 'Bahamas','Bahrain','Bangladesh','Barbados','Belarus','Belgium','Belize','Benin','Bermuda','Bhutan','Bolivia','Bosnia & Herzegovina','Botswana','Brazil','Brunei Darussalam','Bulgaria','Burkina Faso','Myanmar/Burma','Burundi', + 'Cambodia','Cameroon','Canada','Cape Verde','Cayman Islands','Central African Republic','Chad','Chile','Colombia','Comoros','Congo','Costa Rica','Croatia','Cuba','Cyprus','Czech Republic', + 'Democratic Republic of the Congo','Denmark','Djibouti','Dominican Republic','Dominica', + 'Ecuador','Egypt','El Salvador','Equatorial Guinea','Eritrea','Estonia','Ethiopia', + 'Fiji','Finland','France','French Guiana', + 'Gabon','Gambia','Georgia','Germany','Ghana','Great Britain','Greece','Grenada','Guadeloupe','Guatemala','Guinea','Guinea-Bissau','Guyana', + 'Haiti','Honduras','Hungary', + 'Iceland','Indonesia','Iran','Iraq','Israel and the Occupied Territories','Italy','Ivory Coast (Cote d\'Ivoire)', + 'Jamaica','Japan','Jordan', + 'Kazakhstan','Kenya','Kosovo','Kuwait','Kyrgyz Republic (Kyrgyzstan)', + 'Laos','Latvia','Lebanon','Lesotho','Liberia','Libya','Liechtenstein','Lithuania','Luxembourg', + 'Republic of Macedonia','Madagascar','Malawi','Malaysia','Maldives','Mali','Malta','Martinique','Mauritania','Mauritius','Mayotte','Mexico','Moldova, Republic of','Monaco','Mongolia','Montenegro','Montserrat','Morocco','Mozambique', + 'Namibia','Nepal','Netherlands','New Zealand','Nicaragua','Niger','Nigeria','Korea, Democratic Republic of (North Korea)','Norway', + 'Oman', + 'Pacific Islands','Pakistan','Panama','Papua New Guinea','Paraguay','Peru','Philippines','Poland','Portugal','Puerto Rico', + 'Qatar', + 'Reunion','Romania','Russian Federation','Rwanda', + 'Saint Kitts and Nevis','Saint Lucia','Saint Vincent\'s & Grenadines','Samoa','Sao Tome and Principe','Saudi Arabia','Senegal','Serbia','Seychelles','Sierra Leone','Singapore','Slovak Republic (Slovakia)','Slovenia','Solomon Islands','Somalia','South Africa','Korea, Republic of (South Korea)','South Sudan','Spain','Sri Lanka','Sudan','Suriname','Swaziland','Sweden','Switzerland','Syria', + 'Tajikistan','Tanzania','Thailand','Timor Leste','Togo','Trinidad & Tobago','Tunisia','Turkey','Turkmenistan','Turks & Caicos Islands', + 'Uganda','Ukraine','United Arab Emirates','United States of America (USA)','Uruguay','Uzbekistan', + 'Venezuela','Vietnam','Virgin Islands (UK)','Virgin Islands (US)', + 'Yemen', + 'Zambia','Zimbabwe' + ]; + + self.list = ['India', 'China']; + + /*call back method for chip*/ + self.render = function(val) { + var deferred = $q.defer(); + setTimeout(function() { + var ret = [] + for (var i = 0; i < countries.length; i++) { + if (countries[i].toLowerCase().indexOf(val.toLowerCase()) !== -1) { + ret.push(countries.splice(i, 1)[0]); + i--; + } + } + deferred.resolve(ret); // : deferred.reject(val); + }, getDelay()); + return deferred.promise; + }; + + /*call back method for chip delete*/ + self.deleteChip = function(val) { + if (val && val.defer && !val.isFailed) { + countries.push(val.defer); + } + return true; + } + + function getDelay(){ + return (Math.floor(Math.random() * 3) + 1) * 1000; + } + } +})(); diff --git a/src/js/directives/chips.js b/src/js/directives/chips.js index a2a845b..c9a975a 100644 --- a/src/js/directives/chips.js +++ b/src/js/directives/chips.js @@ -75,7 +75,7 @@ return funStr.substr(openParenthesisIndex, closeParenthesisIndex - openParenthesisIndex); } /*@ngInject*/ - function Chips($compile, $timeout, DomUtil) { + function Chips($q, $compile, $timeout, DomUtil) { /*@ngInject*/ function linkFun(scope, iElement, iAttrs, ngModelCtrl, transcludefn) { if ((error = validation(iElement)) !== '') { @@ -117,7 +117,7 @@ } var arr = isArray(response) ? response : [response]; var first = arr.shift(); // get first element, it will be populated to DeferChip - update(arr.map(function(r) { return { defer: r } })); // add all other elements, if any + update(arr, true); // add all other elements, if any model.add(first); return first; }) @@ -127,10 +127,10 @@ update(updatedData); } - function update(data) { + function update(data, defer) { var arr = isArray(data) ? data : [data]; for (var i = 0; i < arr.length; i++) { - scope.chips.list.push(arr[i]); + scope.chips.list.push(defer ? new DeferChip(arr[i], $q.when(arr[i])) : arr[i]); model.add(arr[i]); } }