I'm trying to bind model data from a controller to a directive template. The directive template repeats form input types based on a form object from a controller.
The goal is to use this directive in multiple places and bind the appropriate model to the form as opposed to creating a form each time.
I've found examples using transclusion and isolated scopes, however, each of the examples I've come across seem to have the model properties hardcoded.
Here is a jsfiddle that hopefully explains better what I'm trying to achieve.
app.controller('FormCtrl',function($scope) {
$scope.form = [
{label:'First',type:'text',name:'first_name'},
{label:'Last',type:'text',name:'last_name'}
];
$scope.person = {first_name:'Jimmy',last_name:'Page'};
});
app.directive('formelements',function() {
return {
restrict: 'E',
scope:false,
template: '<div ng-repeat="elements in form"><input type="text" ng-model="field.name"></div>'
}
});
Thanks for any help.