我想使用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>
答案 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。