@DronTat

AngularJS. Проблемы с ng-disabled в цикле ng-repead. Как выбрать определенную строку на редактирование?

При нажатии на карандаш(последний столбец) должна редактироваться ФИО(первый столбец) данной строки.
Вьюшка:
<body ng-controller="indexController">
<div class="col-sm-6">
    <table class="table table-striped">
        <thead>
        <tr>
            <th>ФИО</th>
            <th>Год рождения</th>
            <th>***</th>
        </tr>
        </thead>
        <tbody>
        <tr ng-repeat="item in items">
            <td><input type="text" ng-disabled="disabled.$index" ng-init="disabled.$index=true" value="{{item[0]}}"></td>
            <td>{{item[1]}}</td>
            <td><span class="fas fa-pencil-alt" ng-click="edit($index)"></span></td>
        </tr>
        </tbody>
    </table>
</div>

Контроллер:
testApp.controller('indexController', function ($scope, $http){
        $http({method: 'POST', url: 'http://public/rest_api/index'}).
        then(function success(response) {
            $scope.items = response.data;

        });
        $scope.edit = function (index) {
            console.log(index);
            $scope.disabled = false;
        }
    });

Пробовал так, не работает:
$scope.disabled.index = false;
  • Вопрос задан
  • 59 просмотров
Решения вопроса 1
0xD34F
@0xD34F
А зачем такие сложности? Пусть у вас будет индекс редактируемого элемента, ну и всё:

$scope.edit = function(index) {
  $scope.active = index;
};

ng-disabled="$index !== active"
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы