EDIT - Created a Plunker
I'm trying to make a custom directive to be reused for all of my inputs. Each input would have different options depending on the logged in user (required, hidden, etc), so I thought something like this would be perfect.
I basically have it working like this..
{{username}}
<custom-input name="username" ng-model="username"></custom-input>
app.directive('customInput', function ($compile) {
return {
restrict: 'E',
templateUrl: '/app/shared/views/custom-input.html',
replace: true,
link: function ($scope, element, $attr) {
var options = getFieldOptions($attr.name);
$scope.options = options;
var model = element.attr('ng-model');
return $compile($('input', element).attr('ng-model', model))($scope);
}
};
});
So this works until I add a second input and it shares the options scope from the last one. Scope: true obviously doesn't work in this situation. I need each custom input to keep its own options. Or maybe I'm just going about this all wrong.
This post AngularJS - Create a directive that uses ng-model has been a great help to me, but I can't figure out this last scope issue.