2014-09-04 195 views
-2

我想使用Angularjs顯示和隱藏div,但是我是Angular的新用戶,所以需要一些幫助。顯示一個div並使用Angular js隱藏另一個div

<a href="#">I want to fire event on click of this a tag</a> 
<div style="width: 50px; height: 50px; background-color: red;">I want to show this  element</div> 
<div style="width: 50px; height: 50px; background-color: red;">I want to Hide this element</div> 

回答

0

controller.js:

app.controller('MainCtrl', function($scope) { 
    $scope.showDiv = '1'; 

    $scope.toggleShow = function(){ 
     $scope.showDiv = !$scope.showDiv; 
    } 
}); 

HTML:

<body ng-controller="MainCtrl"> 
    <a href="#" ng-click="toggleShow()">I want to fire event on click of this a tag</a> 
    <div ng-show="showDiv" style="width: 50px; height: 50px; background-color: red;">Show this element</div><br> 
    <div ng-hide="showDiv" style="width: 50px; height: 50px; background-color: green;">Hide this element</div> 
</body> 

這裏是Plunker:http://plnkr.co/edit/DWobFzvas9x4lhaoNfTI

+0

感謝您的回覆,但只是想知道如何顯示點擊標籤 – Sajal 2014-09-04 05:08:33

+0

@Sajal我明白了。在這裏看到你的答案:http://plnkr.co/edit/DWobFzvas9x4lhaoNfTI。 – khemry 2014-09-04 05:16:58