将属性添加到已转换的元素

时间:2017-03-30 06:57:08

标签: angularjs angularjs-directive angularjs-ng-transclude

我有一个表单指令,它扩展了我维护的HTML表单标记的功能,以便为其添加行为。下面给出了它的一个用途,

     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;
            // });
        }
    }

上面我将表单转换为包含在字段集内部,以便在加载表单时用户无法与表单进行交互。

现在,如果我想在被转换的表单中添加autocomplete off属性,那么正确的方法是什么?

1 个答案:

答案 0 :(得分:1)

嗯,这对我有用。

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

在这里,transcluded元素是元素的firstChild。

相关问题