angularjsangularjs-directiveangularjs-ng-transclude

Adding an attribute to a transcluded element


I have a form directive that extends the ability of HTML form tag that I maintain to add behaviours to it . Given below is one use of it ,

     return {
        restrict: 'E',
        replace: true,
        transclude: 'element',
        template: '<fieldset ng-disabled="formLoading" ng-transclude></fieldset>',
        link: function (scope, elem, attr, ctrl, transclude) {
            // elem.on('submit', function () {
            //     $rootScope.formLoading = true;
            // });
        }
    }

Above I transclude the form to contain inside a fieldset so that the user cannot interact with the form if the form is loading .

Now If i want to add an autocomplete off attribute to the form that is transcluded , What would be the right way to do it ?


Solution

  • Well, this worked for me .

            link: function (scope, elem, attr, ctrl, transclude) {
                angular.element(elem[0].firstChild).attr('autocomplete', 'off')
            }
    

    In here transcluded element is the firstChild of the element.