2017-10-09 105 views
-1

我想結束在NG-重複DIV中的按鈕,關閉DIV點擊按鈕通過單擊DIV

HTML

<div ng-repeat="indexVal in vm.flowObject track by $index"> 
    <div ng-show="listItems.title=='Menu'" class="Margin_Set" id="div2" scroll> 
     <button> 
      Close div 
     </button> 
    </div> 
</div> 

JS

$scope.listItems = [{ 
     name: "some name", 
     title: "Menu" 
    }]; 

https://jsfiddle.net/uey4xr5L/

+0

關閉在這個意義上你的意思是隱藏它? –

回答

0

您可以添加一個屬性隱藏並將其設置爲真正上點擊:

<div ng-repeat="indexVal in vm.flowObject track by $index"> 
 
    <div ng-hide="indexVal.hidden == true" class="Margin_Set" id="div2" scroll> 
 
     <button ng-click="indexVal.hidden = true"> Close div </button> 
 
    </div> 
 
</div>

+0

你的方法是什麼?請重新檢查你的答案不起作用 – core114

0

嘗試這樣的。

var app = angular.module('myApp', []); 
 

 
app.controller('myCtrl', function($scope){ 
 
$scope.listItems = [{ 
 
     name: "some name", 
 
     title: "Menu" 
 
    }]; 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.3/angular.min.js"></script> 
 
<body ng-app="myApp"> 
 
<div ng-controller="myCtrl"> <!-- ng-repeat="indexVal in vm.flowObject track by $index" --> 
 
     <p> {{listItems[0]}} </p> 
 
     <button ng-show="listItems[0].close=='true'" ng-click="listItems[0].close = 'false'">Open div</button> 
 
     <div ng-show="(listItems[0].title=='Menu' && listItems[0].close!='true')" class="Margin_Set" id="div2" scroll> 
 
<!-- as per your scenario change the condition.. --> 
 
<p>{{listItems[0].name}}</p> 
 
       <button ng-click="listItems[0].close = 'true'"> 
 
       Close div 
 
       </button> 
 

 
       </div> 
 
       </div> 
 
       </body>