Как узнать, все ли внутренние ng-формы действительны или нет?

0

У меня есть html-код, как это

<div class="section1">
    <div ng-repeat="item in Objs1">
        <ng-form name="myForm">
            <input require name="expression" ng-model="item.exp" />
            <label ng-show="myForm.expression.$error.required" class="error">*-required</label>
        </ng-form>
    </div>
    <button ng-disabled="--if any myForm is invalid--">Add</button>
</div>
<div class="section2">
    <input require name="first" ng-model="firstName" />
    <input require name="first" ng-model="SecondName" />
</div>

Как я могу узнать --if any myForm is invalid--?

Теги:

1 ответ

2
Лучший ответ

ngForm может быть вложенным. Просто добавьте внешний ngForm:

<ng-form name="parentForm">
<div ng-repeat="item in Objs">
    <ng-form name="myForm">
        <input require name="expression" ng-model="item.exp" />
        <label ng-show="myForm.expression.$error.required" class="error">*-required</label>
    </ng-form>
</div>
<button ng-disabled="parentForm.$invalid">Add</button>

</ng-form>
  • 0
    Это огромная форма, и она может быть недействительной в каком-то другом месте, поэтому не может использовать parentForm. $ Invalid
  • 0
    Тогда мне непонятно, что вы спрашиваете
Показать ещё 3 комментария

Ещё вопросы

Сообщество Overcoder
Наверх
Меню