如何在角度中显示和隐藏DIV

时间:2013-09-14 07:31:06

标签: javascript angularjs

我有两个div

<div id = 'a'>
</div>
<div id = 'b'>
</div>

点击“添加”按钮我要隐藏div a并显示div b

1 个答案:

答案 0 :(得分:9)

您可以调整您的html标记:

<div ng-controller="controller">     
    <div id = 'a' ng-show="showA">
    </div>
    <div id = 'b' ng-show="showB">
    </div>
    <button ng-click="add()">Add</button>
</div>

然后,在你的控制器中,有类似的东西:

function controller($scope) {
    $scope.showA = true;
    $scope.showB = false;

    $scope.add = function() {
        $scope.showA = false;
        $scope.showB = true;
    };
}