array_join.ts 663 B

123456789101112131415161718192021222324252627282930
  1. import { isArray } 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: any, element: any, attr: any, ngModel: any) => {
  9. function split_array(text: string) {
  10. return (text || '').split(',');
  11. }
  12. function join_array(text: string) {
  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);