Skip to content
This repository has been archived by the owner on Nov 22, 2021. It is now read-only.

Commit

Permalink
feat(autocomplete): Add support for $http promises
Browse files Browse the repository at this point in the history
Add support for $http promises so they can be returned as is by the
source option expression without requiring its value to be converted.

Closes #38.
  • Loading branch information
mbenford committed Dec 28, 2013
1 parent 246b105 commit adaf658
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 14 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ You can also use Bower to install all files at once. Just run `bower install ng-
.controller('MyCtrl', function($scope, $http) {
$scope.tags = ['just','some','cool','tags'];
$scope.loadTags = function(query) {
return $http.get('/tags?query=' + query).then(function(response) {
return response.data;
});
return $http.get('/tags?query=' + query);
};
});
</script>
Expand Down
12 changes: 5 additions & 7 deletions build/ng-tags-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ tagsInput.directive('tagsInput', ["$timeout","$document","tiConfiguration", func
},
trigger: function(name, args) {
angular.forEach(events[name], function(handler) {
handler.call(null, args);
handler.call(null, args);
});
}
};
Expand Down Expand Up @@ -298,9 +298,6 @@ tagsInput.directive('autoComplete', ["$document","$timeout","$sce","tiConfigurat
self.selected = null;
self.visible = true;
};
self.hide = function() {
self.visible = false;
};
self.load = function(query, tags) {
if (query.length < options.minLength) {
self.reset();
Expand All @@ -319,7 +316,7 @@ tagsInput.directive('autoComplete', ["$document","$timeout","$sce","tiConfigurat
return;
}

self.items = getDifference(items, tags);
self.items = getDifference(items.data || items, tags);
if (self.items.length > 0) {
self.show();
}
Expand Down Expand Up @@ -564,9 +561,10 @@ tagsInput.service('tiConfiguration', ["$interpolate", function($interpolate) {
};
}]);


/* HTML templates */
tagsInput.run(["$templateCache", function($templateCache) {

$templateCache.put('ngTagsInput/tags-input.html',
$templateCache.put('ngTagsInput/tags-input.html',
"<div class=\"ngTagsInput\" tabindex=\"-1\" ng-class=\"options.customClass\" ti-transclude-append=\"\"><div class=\"tags\" ng-class=\"{focused: hasFocus}\"><ul class=\"tag-list\"><li class=\"tag-item\" ng-repeat=\"tag in tags\" ng-class=\"getCssClass($index)\"><span>{{tag}}</span> <button type=\"button\" ng-click=\"remove($index)\">{{options.removeTagSymbol}}</button></li></ul><input class=\"tag-input\" placeholder=\"{{options.placeholder}}\" maxlength=\"{{options.maxLength}}\" tabindex=\"{{options.tabindex}}\" ng-model=\"newTag\" ng-change=\"newTagChange()\" ti-autosize=\"\"></div></div>"
);

Expand Down
Binary file modified build/ng-tags-input.min.zip
Binary file not shown.
Binary file modified build/ng-tags-input.zip
Binary file not shown.
5 changes: 1 addition & 4 deletions src/auto-complete.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ tagsInput.directive('autoComplete', function($document, $timeout, $sce, tiConfig
self.selected = null;
self.visible = true;
};
self.hide = function() {
self.visible = false;
};
self.load = function(query, tags) {
if (query.length < options.minLength) {
self.reset();
Expand All @@ -70,7 +67,7 @@ tagsInput.directive('autoComplete', function($document, $timeout, $sce, tiConfig
return;
}

self.items = getDifference(items, tags);
self.items = getDifference(items.data || items, tags);
if (self.items.length > 0) {
self.show();
}
Expand Down
11 changes: 11 additions & 0 deletions test/auto-complete.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,17 @@ describe('autocomplete-directive', function() {
expect(getSuggestionText(1)).toBe('Item2');
});

it('renders all elements returned by the load function that aren\'t already added ($http promise)', function() {
// Act
tagsInput.getTags.andReturn(['Item3']);
loadSuggestions({ data: ['Item1','Item2','Item3'] });

// Assert
expect(getSuggestions().length).toBe(2);
expect(getSuggestionText(0)).toBe('Item1');
expect(getSuggestionText(1)).toBe('Item2');
});

it('shows the suggestions list when there are items to show', function() {
// Act
loadSuggestions(['Item1']);
Expand Down

0 comments on commit adaf658

Please sign in to comment.