array_join.ts 665 B

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