R
R
rtplv2017-01-19 21:31:10
Angular
rtplv, 2017-01-19 21:31:10

Angular. How to implement ng-show, ng-hide in a specific iteration?

I'm new to Angular, so don't throw too many slippers.
The point is the following. There is a list of addresses. When you click on one of the lines, you need to hide the cells with info and display the input for editing. Everything works, but it only works on all lines at once, but you need one.

<table class="table table-striped col-md-6">
        <tr>
          <th class="col-md-5">Полный адрес</th>
          <th class="col-md-3">Координаты</th>
          <th class="col-md-4">Комментарий</th>
          <th></th>
        </tr>
        <tr ng-repeat="data in addressList"  ng-click="addressEditor()" ng-hide="editorEnabled">
          <td>{{data.address}}</td>
          <td>{{data.latitude}} / {{data.longitude}}</td>
          <td>{{data.description}}</td>
          <td class="col-sm-2"><button class="btn btn-danger" ng-click="removeAddress(data)"><span class="glyphicon glyphicon-trash"></span></button></td>
          </tr>
        <tr ng-repeat="item in addressList" ng-show="editorEnabled">
          <td><input type="text" ng-model="item.address"></td>
          <td><input type="text" ng-model="item.latitude"><input  type="text" ng-model="item.longitude"></td>
          <td><input type="text" ng-model="item.description"></td>
          <td><button class="btn btn-success" ng-click="close()">Сохранить</button><button class="btn btn-danger" ng-click="close()">Отмена</button></td>
        </tr>
      </table>

And the JS code:
$scope.editorEnabled = false;

         $scope.addressEditor = function() {
           $scope.editorEnabled = true;
         };

         $scope.close = function () {
           $scope.editorEnabled = false;
         };

How to apply ng-hide and ng-show to only one line? It seems like through id. If possible, show with an example.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Luzanov, 2017-01-19
@rtplv

<table class="table table-striped col-md-6">
    <tr>
        <th class="col-md-5">Полный адрес</th>
        <th class="col-md-3">Координаты</th>
        <th class="col-md-4">Комментарий</th>
        <th></th>
    </tr>
    <tr
    ng-init="data.edit = false"
    ng-repeat="data in addressList"
    ng-click="data.edit = !data.edit"
    ng-hide="data.edit">
        <td>{{data.address}}</td>
        <td>{{data.latitude}} / {{data.longitude}}</td>
        <td>{{data.description}}</td>
        <td class="col-sm-2">
            <button class="btn btn-danger" ng-click="removeAddress(data)">
                <span class="glyphicon glyphicon-trash"></span>
            </button>
        </td>
    </tr>
    <tr ng-repeat="item in addressList" ng-show="item.edit">
        <td><input type="text" ng-model="item.address"></td>
        <td><input type="text" ng-model="item.latitude"><input type="text" ng-model="item.longitude"></td>
        <td><input type="text" ng-model="item.description"></td>
        <td><button class="btn btn-success" ng-click="close()">Сохранить</button><button class="btn btn-danger" ng-click="close()">Отмена</button></td>
    </tr>
</table>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question