app.directive('formInput', function(translations){ return { restrict: 'E', transclude: true, replace: true, template: '<input class="form-control" ng-model=vm.user**[formGroup.attribute]**></input>', require: [ '^formFor', '^formGroup' ], link: function($scope, $element, $attrs, $ctrls) { var formForCtrl = $ctrls[0]; var formGroupCtrl = $ctrls[1]; $attrs.$set('id', formGroupCtrl.inputId(formForCtrl.name)); $attrs.$set('placeholder', translations.User[formGroupCtrl.attribute]); } } }); 

namely, in the line ng-model=vm.user. + formGroup.attribute

    1 answer 1

    To use the value in the template, it must be added either to the Osp, or the controller, for example:

     app.directive('formInput', function(translations){ return { restrict: 'E', transclude: true, replace: true, template: '<input class="form-control" ng-model="vm.user[formGroupAttribute]"></input>', require: [ '^formFor', '^formGroup' ], link: function($scope, $element, $attrs, $ctrls) { var formForCtrl = $ctrls[0]; var formGroupCtrl = $ctrls[1]; $scope.formGroupAttribute = formGroupCtrl.attribute; $attrs.$set('id', formGroupCtrl.inputId(formForCtrl.name)); $attrs.$set('placeholder', translations.User[formGroupCtrl.attribute]); } } });