显示一个div并使用Angular js隐藏另一个div

时间:2014-09-04 04:42:59

标签: angularjs

我想使用Angularjs显示和隐藏div,但我是Angular中的新手,所以需要一些帮助,先谢谢。

<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>

1 个答案:

答案 0 :(得分: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