array_join.ts 698 B

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