2017-10-09 104 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>