Artur Bekerov2014-02-05 10:36:49
Artur Bekerov, 2014-02-05 10:36:49

Angular pristine in ng-repeat: why doesn't the code work?

Please tell me why the code is not working.

<table class="table table-hover">
        <tr ng-repeat="contact in contacts">
            <form name="contactEditForm{{$index}}">
                <input type="text" class="form-control" placeholder="ФИО" ng-model="contact.name">
                <input type="text" class="form-control" placeholder="Дожность" ng:model="contact.position" >
                <button ng-hide="contactEditForm{{$index}}.$pristine" class="save btn btn-primary" ng:click="editContact()">Сохранить</button>

                <input class="form-control" placeholder="Email" ng:model="contact.email" >
                <input type="text" class="form-control" placeholder="Телефон" ng:model="contact.phone" >
                <input type="text" class="form-control" placeholder="Мобильный" ng:model="contact.mobile" >
            <td><textarea type="text" class="form-control" placeholder="Описание" ng:model="contact.feature" ></textarea></td>
            <td><span class="glyphicon glyphicon-remove" ng:click="deleteContact(contact.id)"></span></td>


There is a similar form. but which is not displayed through ng-repeat and when the form changes, a button appears.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Ruslan Lopatin, 2014-02-05

contactEditForm{{$index}}.$pristine- syntax error. Such an expression is not allowed in JavaScript.

kompi, 2014-02-05

Google the answer for you: stackoverflow
If you are too lazy to read, then without creating anything new, you can do it this way:

<tr ng-repeat="contact in contacts">
            <form name="contact.contactEditForm">
       <button ng-hide="сontact.contactEditForm.$pristine" class="save btn btn-primary" ng:click="editContact()">Сохранить</button>

In general, here is the solution to your problems (use ng-form) plunker .
The only thing I don't understand is why ng-form doesn't work immediately after tr, i.e. I had to wrap everything in td.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question