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