как нацелить текущий элемент области в ng-repeat в угловых

0

В приведенном ниже коде внутри родительского div [class= timeAllot] везде, где я делаю изменение (на кнопках ввода, таких как am, pm, имя и т.д.), Тогда кнопка div [div class= "buttons"] элемент shoud будет видимым. Сначала, когда страница загружается, она должна быть невидимой.

Он не должен делать все кнопки класса div видимыми, когда я делаю изменения в первом div, он должен делать только то, что div я меняет. Я имею в виду, если я изменил первый div timeAllot, он должен сделать только невидимый первый div [div class= "buttons"]

Проблема заключается в том, что он делает все элементы div видимыми.

на моем контроллере у меня есть этот код:

$scope.items = [{hours: 24, place: 'india'}, {hours: 24, place: 'uk'}, {hours: 24, place: 'USA'}];
$scope.dataItems = ['Items1', 'Item2', 'Item3'];

$scope.displaySaveCancel = false;

$scope.checkthiStuff = function(indexValue){
    console.log("Check this stufff...", indexValue);
    $scope.displaySaveCancel = true;

};

в html

<div class="timeAllot" ng-repeat="item in items" ng-change="checkthiStuff($index)">

    Name: <input type="text" name="name" ng-model="name"/>

    <div class="infos" ng-repeat="data in dataItems">
       AM: <input type="text" name="am" ng-model="am"/>
       PM: <input type="text" name="pm" ng-model="pm"/>
    </div>

    <div class="buttons" ng-show="displaySaveCancel === true">
    <button>save</button>
    <button>cancel</button>
    </div>

</div>
  • 0
    Не могли бы вы предоставить плункер, чтобы показать вашу проблему?

1 ответ

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

Используйте $index текущего элемента,

<div class="infos" >
   AM: <input type="text" data-ng-change="checkthiStuff($index)" name="am" ng-model="am"/>
   PM: <input type="text" data-ng-change="checkthiStuff($index)" name="pm" ng-model="pm"/>
</div>   

<div class="buttons" ng-show="currentIndex === $index">
    <button>save</button>
    <button>cancel</button>
</div>

В контроллере,

$scope.currentIndex = -1;
$scope.checkthiStuff = function(indexValue){
    $scope.currentIndex = indexValue; 

};
  • 0
    не могли бы вы посмотреть на мой код, я сделал некоторые изменения в моем коде.

Ещё вопросы

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