grafana/public/app/core/directives/array_join.ts

35 lines
716 B
TypeScript
Raw Normal View History

///<reference path="../../headers/common.d.ts" />
import angular = require('angular');
import _ = require('lodash');
import coreModule = require('../core_module');
export function arrayJoin() {
2015-09-11 14:04:02 -05:00
'use strict';
return {
restrict: 'A',
require: 'ngModel',
link: function(scope, element, attr, ngModel) {
function split_array(text) {
return (text || '').split(',');
}
function join_array(text) {
2015-09-11 14:04:02 -05:00
if (_.isArray(text)) {
return (text || '').join(',');
} else {
return text;
}
}
ngModel.$parsers.push(split_array);
ngModel.$formatters.push(join_array);
}
};
}
coreModule.directive('arrayJoin', arrayJoin);