Sha256: dc5b674a83d815243c84912bdba411e5002bf1080ffaa9456667e5d318934309
Contents?: true
Size: 1.08 KB
Versions: 32
Compression:
Stored size: 1.08 KB
Contents
!(angular => { 'use strict'; class SelectionTagInput { constructor(options) { this._items = this._makeItemsFn(options.items, options.iteratee); this._itemField = options.itemField; this.selectedTags = []; } add(tag) { _.each(this._items(), item => { item[this._itemField].unshift(tag.text); }); } remove(tag) { _.each(this._items(), item => { item[this._itemField] = _.reject(item[this._itemField], itemTag => { return tag.text === itemTag; }); }); } onSelection() { this.selectedTags = _.reduce(this._items(), (acc, item) => { return _.uniq(acc.concat(item[this._itemField])); }, []); } // private methods _makeItemsFn(items, _iteratee) { let rawItems = _.isFunction(items) ? items : () => items; let iteratee = _iteratee; return _.isFunction(iteratee) ? () => _.map(rawItems(), iteratee) : rawItems; } } angular.module('alephServices.selectionTagInput', []).service('SelectionTagInput', () => SelectionTagInput); }(angular));
Version data entries
32 entries across 16 versions & 1 rubygems