This repository has been archived by the owner on Nov 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 540
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tagsInput): Add custom template support
Add custom template support for the tagsInput directive so it matches the same functionality of the autoComplete directive. Same rules apply here: tag data is available to the template via the data property, tag index is available through $index and a tag can be deleted by calling the $removeTag function.
- Loading branch information
Showing
8 changed files
with
208 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use strict'; | ||
|
||
/** | ||
* @ngdoc directive | ||
* @name tiTagItem | ||
* @module ngTagsInput | ||
* | ||
* @description | ||
* Represents a tag item. Used internally by the tagsInput directive. | ||
*/ | ||
tagsInput.directive('tiTagItem', function(tiUtil) { | ||
return { | ||
restrict: 'E', | ||
require: '^tagsInput', | ||
template: '<ng-include src="$$template"></ng-include>', | ||
scope: { data: '=' }, | ||
link: function(scope, element, attrs, tagsInputCtrl) { | ||
var tagsInput = tagsInputCtrl.registerTagItem(), | ||
options = tagsInput.getOptions(); | ||
|
||
scope.$$template = options.template; | ||
scope.$$removeTagSymbol = options.removeTagSymbol; | ||
|
||
scope.$getDisplayText = function() { | ||
return tiUtil.safeToString(scope.data[options.displayProperty]); | ||
}; | ||
scope.$removeTag = function() { | ||
tagsInput.removeTag(scope.$index); | ||
}; | ||
|
||
scope.$watch('$parent.$index', function(value) { | ||
scope.$index = value; | ||
}); | ||
} | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<span ng-bind="$getDisplayText()"></span> | ||
<a class="remove-button" ng-click="$removeTag()" ng-bind="$$removeTagSymbol"></a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
45e5d99
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just learned how to dynamically load templates into a component with TDD thanks to that commit :)
Thank you! @mbenford 👍