How to hide a div by clicking a button? (Disclosed)

In my angular.js tutorial project, I want to hide one div and show another when I click the button. In this code, I would like the first div to be hidden on click (or even destroyed?) And the second div to be shown. Basically, I want the user interface to go from page 1 to page 2 in my application. How to do it?

Index.html

  <ion-content ng-controller="StartpageCtrl">

      <div class="list card" id="startCard" ng-show="showstartCard">
          <div class="item item-image item item-text-wrap">
              Card 1
          </div>
      </div>
      <div class="list card" id="secondCard" ng-show="showsecondCard">
          <div class="item item-image item item-text-wrap">
              Card 2
          </div>
      </div>

      <button ng-click="hideCard()" class="button button-full button-calm button icon-right ion-chevron-right">
          Start now
      </button>

  </ion-content>

controllers.js

.controller("StartpageCtrl", funcion($scope){
    $scope.showstartCard = true;
    $scope.showsecondCard = false;

    $scope.hideCard = function() {
        $scope.showstartCard = false;
        $scope.showsecondCard = true;
    };
});

When I start the page, I see "Map 2" and nothing happens when I click the button. What I wanted to see was "Card 1" and for this go to "Card 2" when I press the button ...

UPDATE SEP 10 23:30 CET Now it works fine. I forgot to add links to controllers.js in app.js angular.module, as well as a script tag in index.html.

+4
2
Using angular:   
 HTML file:
    <td><a href="#" ng-click="showDetails =! showDetails">Source Doc..</a>
                <div id="mydiv" ng-show="showDetails">
                    <div id="mydiv-container">
                        <div id="mydiv-content">
                            <a href="#" ng-click="showDetails =! showDetails">Close</a>
                            <br>
                            hello
                        </div>
                    </div>
                </div>

                </td>



    css file:
    body {
        height: 100%;
        background-color: #F0F0F0;
        font-family: Arial, sans-serif;
    }
    #mydiv {
        width: 100%;
        height: 100%;
        overflow: hidden;
        left: 100px;
        top: 150px;
        position: absolute;
        opacity: 0.95;

    }
    #mydiv-container {
        margin-left: auto;
        margin-right: auto;
    }
    #mydiv-content {
        width: 70%;
        padding: 20px;
        background-color: white;
        border: 1px solid #6089F7;
    }
    a {
        color: #5874BF;
        text-decoration: none;
    }
    a:hover {
        color: #112763;
    }
+1

, , - CSS JS.

<button ng-click="isDetailOpen = !isDetailOpen"
        ng-class="!isDetailOpen ? 'ion-ios-arrow-down' : 'ion-ios-arrow-up'"
        class="button button-clear button-positive icon-right">
  <span ng-show="!isDetailOpen">More Detail</span>
  <span ng-show="isDetailOpen">Less Detail</span>
</button>
<div ng-show="isDetailOpen">
  <p>Per ad ferri dicta, omnis laudem dicunt duo an. Ex pri solum definitiones.</p>
</div>

Angular - .

0

All Articles