Dynamic form name attribute <input type=“text” name=“{{ variable-name }}” /> in Angularjs

后端 未结 4 1444
忘掉有多难
忘掉有多难 2020-11-29 08:07

How would someone use formName.inputName.$valid when the \"inputName\" was dynamically created?

  
4条回答
  •  囚心锁ツ
    2020-11-29 08:57

    work for me with angular 1.2.7

    directive:

    var DynamicName = function() {
        return {
            restrict: 'A',
            priority: -1,
            require: ['ngModel'],
            link: function (scope, element, attr, ngModel) {
                ngModel[0].$name = attr.name;
            }
        };
    };
    
    app.directive('dynamicName', DynamicName);
    

    howtouse:

提交回复
热议问题