array_join.ts 619 B

1234567891011121314151617181920212223242526272829
  1. import _ from 'lodash';
  2. import coreModule from '../core_module';
  3. export function arrayJoin() {
  4. 'use strict';
  5. return {
  6. restrict: 'A',
  7. require: 'ngModel',
  8. link: (scope, element, attr, ngModel) => {
  9. function split_array(text) {
  10. return (text || '').split(',');
  11. }
  12. function join_array(text) {
  13. if (_.isArray(text)) {
  14. return ((text || '') as any).join(',');
  15. } else {
  16. return text;
  17. }
  18. }
  19. ngModel.$parsers.push(split_array);
  20. ngModel.$formatters.push(join_array);
  21. },
  22. };
  23. }
  24. coreModule.directive('arrayJoin', arrayJoin);