There are several ways to do this.
1) Display the variable account with =
http://plnkr.co/edit/DxsipWRj0AJe6Yi3bhse
JS:
app.directive('formControl', [function(){ return { restrict: 'EA', template: '<div ng-transclude></div>{{account.name}}', scope: { account: '=' }, transclude: true, link: function(scope, element, attrs){ scope.account={}; console.log('SCOPE: ', scope) } }; }]);
HTML:
<form-control account='account'> <label for="name">Enter Name:</label> <input name="name" ng-model="account.name" \> </form-control>
2) Using the transclude function:
This is similar to what ngIf and ngRepeat . ngRepeat actually decorates each area with $index and similar values, just like you want to decorate your area with account .
http://plnkr.co/edit/cZjWqIgO23nzc0kMZA57
JS:
app.directive('formControl', ['$animate', function($animate){ return { restrict: 'EA', transclude: 'element', link: function(scope, element, attrs, ctrl, transclude){ //this creates a new scope that inherits from the parent scope //that new scope will be what you'll be working with inside your //transcluded html transclude(function (clone, scope) { scope.account = {name:'foobar'}; $animate.enter(clone, null, element); console.log('SCOPE: ', scope) }); } }; }]);
HTML:
<form-control> <label for="name">Enter Name:</label> <input name="name" ng-model="account.name" \><br> {{account.name}} </form-control>