K-Infected K-Infected - 3 months ago 20
Javascript Question

AngularJS: show other div and hide current div on click of a button

I have a

<div>
which contains a
<button>
. When this button is clicked, I want this
<div>
to be hidden and another new
<div>
to be shown in place of the current
<div>
. Also, the new
<div>
contains a
<button>
, which when clicked opens the old
<div>
. This will enable me to open one
<div>
at a time on click of the
<button>
present in those
<div>
. Can anyone tell me how to do this in AngularJS?

This picture shows my requirement

Answer
<body ng-init="showDiv = true">  

  <div ng-show="showDiv">
       <h1>Div 1</h1>
       <button ng-click="showDiv = false">Show Div 2</button>
    </div>
    <div ng-hide="showDiv">
        <h1>Div 2</h1>
       <button ng-click="showDiv = true">Show Div 1</button>
    </div>

</body>

CodePen: https://codepen.io/RaymondAtivie/pen/OXYRyE