(function () { "use strict"; angular.module('fix.name', []) /** * Directive adds ability to use expression in form control names * @example fix-name="{{'name_' + lang.id}}" */ .directive('fixName', function () { return { priority: 99, require: ['ngModel', '^?form'], link: function (scope, element, attr, ctrls) { attr.$observe('fixName', function (value) { var modelCtrl = ctrls[0], formCtrl = ctrls[1]; if (value) { attr.$set('name', value); modelCtrl.$name = value; if (formCtrl) { formCtrl[modelCtrl.$name] = modelCtrl; } } // todo: check if we need to fix IE // element.prop('name', attr['name']); }); } }; }); })();