2015-09-05 277 views
-1

問題是我的所有div在click打開。打開的彈出窗口點擊

我只想要該div打開其內容點擊。

openBigDiv功能是:

$scope.IsHidden = true; 

$scope.openBigDiv = function { 
    $scope.IsHidden = $scope.IsHidden ? false : true; 
} 

我使用ng-click調用DIV功能。

+0

你能發佈html嗎? – Matt

+0

請找我的HTML

{{appreciate.appre}}

{{appreciate.custContent}}
{{appreciate.by}}
Ziva

回答

0

您可以使用可視性標誌陣列

HTML:

<div ng-app="testApp"> 
    <div ng-controller="testController"> 
     <div> 
      <button ng-click="showElem('elem1');">Show elem1</button> 
      <div ng-show="IsElemVisible('elem1')">elem1</div> 
      <button ng-click="showElem('elem2');">Show elem2</button> 
      <div ng-show="IsElemVisible('elem2')">elem2</div> 
     </div> 
    </div> 
</div> 

或HTML,如果你想使用循環:

<div ng-app="testApp" ng-init="myElems=['elem1','elem2','elem3']"> 
    <div ng-controller="testController"> 
     <div ng-repeat="elem in myElems"> 
      <button ng-click="showElem(elem);">Show {{elem}}</button> 
      <div ng-show="IsElemVisible(elem)">{{elem}}</div> 
     </div> 
    </div> 
</div> 

的Javascript:

var app = angular.module('testApp', []); 
app.controller('testController', function ($scope, $location, $rootScope, $log) { 
    $scope.hiddenElements = []; 
    $scope.IsElemVisible = function(elemId) { 
     return $scope.hiddenElements[elemId]; 
    } 
    $scope.showElem = function (elemId) { 
     $scope.hiddenElements[elemId] = true; 
    } 
}); 

Fiddle

+0

謝謝它爲我工作:) – Ziva

相關問題