angular ng-display isn't functioning correctly

I'm currently facing an issue with Angular version 1.4.5 where only the element "termsinfo" is being displayed while the others are not showing up at all. If anyone can assist me, I will post the code in a simulation for troubleshooting.


// Code goes here
var app = angular.module('app',[]);
app.controller('legalController', function ($timeout, $scope) {
    $scope.termsinfo = true;
    $scope.cookiesinfo = false;
    $scope.privacy = false;
    $timeout(function () {
        $scope.terms = function () {
            $scope.termsinfo = true;
            $scope.cookiesinfo = false;
            $scope.privacy = false;
        }
        $scope.cookies = function () {
            $scope.termsinfo = false;
            $scope.cookiesinfo = true;
            $scope.privacy = false;
        }
        $scope.private = function () {
            $scope.termsinfo = false;
            $scope.cookiesinfo = false;
            $scope.privacy = true;
        }
    });

});
<!DOCTYPE html>
<html>

<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>
<link href="style.css" rel="stylesheet" />
<script src="script.js"></script>
</head>

<body ng-app="app" ng-controller="legalController">
<div id="splash">
<div id="intro-container">
<h1>legal</h1>
<h3>Find legal information and resourcesservices</h3>
</div>

<div id="splash-overlay"></div>
</div>
<div id="legal-sections">
<div id="switcher">
<ul>
<li><a id="open-terms-use" ng-click="terms()">Terms of Use</a></li>
<!--<li><a id="open-security">Security</a></li>-->
<li><a id="open-cookies" ng-click="cookies()">Cookies Policy</a></li>
<li><a id="open-private" ng-click="private()">Private Policy</a></li>
</ul>
</div>
<div id="terms-use" ng-show="termsinfo">
<section>
<div class="container">
<div class="Ehl-Page-Header">
<h1 class="h2">Terms of use</h1>
</div></div>

</section>
</div>
<div id="security">
</div>
<div id="cookies" style="display: none;" ng-show="cookiesinfo">
<div>
<section class="clear container-fluid" id="Cookies-Top">
<div class="Bg-Mask"></div>
<div class="container">
<h1 class="h2">Cookies</h1>
</div>

</section>
</div>
</div>
<div id="private-policy" style="display: none;"  ng-show="privacy">
<div>
<section>
<div class="container">
<div class="Ehl-Page-Header">
<h1 class="h2">Privacy</h1>
</div></div>
</section>

</div>
</div>
</div>
</body>

</html>

Answer №1

Instead of using style="display: none;", simply utilize ng-show

// Insert your code here
var app = angular.module('app',[]);
app.controller('legalController', function ($timeout, $scope) {
    $scope.termsinfo = true;
    $scope.cookiesinfo = false;
    $scope.privacy = false;
    $timeout(function () {
        $scope.terms = function () {
            $scope.termsinfo = true;
            $scope.cookiesinfo = false;
            $scope.privacy = false;
        }
        $scope.cookies = function () {
            $scope.termsinfo = false;
            $scope.cookiesinfo = true;
            $scope.privacy = false;
        }
        $scope.private = function () {
            $scope.termsinfo = false;
            $scope.cookiesinfo = false;
            $scope.privacy = true;
        }
    });
  
});
<!DOCTYPE html>
<html>

  <head>
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>
    <link href="style.css" rel="stylesheet" />
    <script src="script.js"></script>
  </head>

  <body ng-app="app" ng-controller="legalController">
    <div id="splash">
    <div id="intro-container">
        <h1>legal</h1>
        <h3>Find legal information and resourcesservices</h3>
    </div>

    <div id="splash-overlay"></div>
</div>
<div id="legal-sections">
    <div id="switcher">
        <ul>
            <li><a id="open-terms-use" ng-click="terms()">Terms of Use</a></li>
<!--            <li><a id="open-security">Security</a></li>-->
            <li><a id="open-cookies" ng-click="cookies()">Cookies Policy</a></li>
            <li><a id="open-private" ng-click="private()">Private Policy</a></li>
        </ul>
    </div>
    <div id="terms-use" ng-show="termsinfo">
        <section>
            <div class="container">
                <div class="Ehl-Page-Header">
                    <h1 class="h2">Terms of use</h1>
                </div></div>

        </section>
    </div>
    <div id="security">
    </div>
    <div id="cookies" ng-show="cookiesinfo">
        <div>
            <section class="clear container-fluid" id="Cookies-Top">
                <div class="Bg-Mask"></div>
                <div class="container">
                    <h1 class="h2">Cookies</h1>
                </div>
  
            </section>
        </div>
    </div>
    <div id="private-policy" ng-show="privacy">
        <div>
            <section>
                <div class="container">
                <div class="Ehl-Page-Header">
                    <h1 class="h2">Privacy</h1>
                </div></div>
            </section>
        
    </div>
</div>
</div>
  </body>

</html>

Answer №2

To avoid conflicts, it is recommended to eliminate the inline style code style="display: none;" as Angular directives do not overwrite existing inline styles.

Answer №3

The $scope.terms function is not being executed properly -

 $timeout(function () {
        $scope.terms = function () {
            $scope.termsinfo = true;
            $scope.cookiesinfo = false;
            $scope.privacy = false;
        }() //make sure to include these braces to execute
        $scope.cookies = function () {
            $scope.termsinfo = false;
            $scope.cookiesinfo = true;
            $scope.privacy = false;
        }() //make sure to include these braces to execute
        $scope.private = function () {
            $scope.termsinfo = false;
            $scope.cookiesinfo = false;
            $scope.privacy = true;
        }()
    });

Oops!! I forgot to mention, you also need to remove the display:none attribute

Answer №4

It is recommended to remove the style attribute "display: none;" as it will be automatically added by ng-show when the id expression is false.

<!DOCTYPE html>
<html>

  <head>
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>
    <link href="style.css" rel="stylesheet" />
    <script src="script.js"></script>
  </head>

  <body ng-app="app" ng-controller="legalController">
    <div id="splash">
    <div id="intro-container">
        <h1>legal</h1>
        <h3>Find legal information and resourcesservices</h3>
    </div>

    <div id="splash-overlay"></div>
</div>
<div id="legal-sections">
    <div id="switcher">
        <ul>
            <li><a id="open-terms-use" ng-click="terms()">Terms of Use</a></li>
<!--            <li><a id="open-security">Security</a></li>-->
            <li><a id="open-cookies" ng-click="cookies()">Cookies Policy</a></li>
            <li><a id="open-private" ng-click="private()">Private Policy</a></li>
        </ul>
    </div>
    <div id="terms-use" ng-show="termsinfo">
        <section>
            <div class="container">
                <div class="Ehl-Page-Header">
                    <h1 class="h2">Terms of use</h1>
                </div></div>

        </section>
    </div>
    <div id="security">
    </div>
    <div id="cookies"  ng-show="cookiesinfo">
        <div>
            <section class="clear container-fluid" id="Cookies-Top">
                <div class="Bg-Mask"></div>
                <div class="container">
                    <h1 class="h2">Cookies</h1>
                </div>

            </section>
        </div>
    </div>
    <div id="private-policy"  ng-show="privacy">
        <div>
            <section>
                <div class="container">
                <div class="Ehl-Page-Header">
                    <h1 class="h2">Privacy</h1>
                </div></div>
            </section>

    </div>
</div>
</div>
  </body>

</html>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Use AngularJS to smoothly transition from one page to another within the index.html file

I'm currently facing an issue with navigating from my index.html page to the customer.html page using AngularJS within the Angular framework. I have been relying on HTML links for navigation, but now I need to switch to angular routing in order to mak ...

Updating values in a mat-select component using the Angular patchValue method

Within my Angular 7 application, I am utilizing the mat-select component from Angular Material in a reactive form. This is how the view appears: <mat-form-field class="col-md-3" color="warn"> <mat-select placeholder="Selectionner la ...

Is it possible to have Javascript trigger audible notifications?

Is there a way to trigger a sound when a user clicks on a link using JavaScript and jQuery? ...

Exploring the Dynamic Connection: AngularJS and MongoDB

As someone who is new to MEAN stack, I am currently working on creating a simple one-page application. My goal is to connect to MongoDB and retrieve values from a specific collection using a controller. During my search for an answer, I stumbled upon this ...

Step-by-Step Guide on Dividing Table Row Data into Two Distinct Tables

At present, I have created a dynamic table that retrieves data from the database using forms in Django. I'm facing an issue with this table as even though there are 7 columns, only 2 of them are visible. However, all 5 hidden columns do contain impor ...

error message: The file you are trying to access does not exist due to the

I seem to be facing an issue with my package.json file. I am trying to include a new "command" in a correctly written package. Specifically, I am looking to add a command that will load test data, so I updated the scripts section as follows: "load-test-da ...

Transferring PHP array data to JavaScript using echo

I'm currently in the process of working on a project that requires extracting data from a database and converting it into a JavaScript array. This array will be used to dynamically update a graph. Below is the PHP code I have written to retrieve the ...

What is the best way to retrieve a Rails variable that is restricted to a specific partial?

As a newcomer to Ruby on Rails, I find myself struggling to grasp the larger concept. Any assistance you can offer would be greatly appreciated. Within my application.html.haml file, I utilize =yield to pull content from ranked.html.haml. Currently, this ...

Having trouble with the Wordpress JS CSS combination not functioning properly and unable to determine the cause

I recently set up a page on my WordPress site using the Twenty Seventeen theme. At the top of the page, I created a toolbar for users to easily adjust the font size and background color. Check out the image below for reference: See Image for Bar Here&apo ...

Using buttons in Angular, you can easily apply filters to an ng-repeat loop

Is there a way to filter an ng-repeat using buttons (which will be replaced by inputs later), but encountering an issue where everything disappears when a filter button is clicked? Also, when clicking the button with no filters, everything remains hidden. ...

Problems arise when making a second call back to the ajax web method

I have an ajax method that helps me find the selected row from a table and display the information in a series of fields. The issue I am facing is that the first time the call is made, it works fine. However, when I search for another record, the data is n ...

Can Node.js create objects with functions dynamically?

My Node.js application interacts with another server app to retrieve information about instances of specific objects. This information is organized as a tree structure that includes details such as node type (method or property), method arguments, node ID, ...

Adjust the background image height to match the height of the viewport

In my Nuxt.js project with Vuetify.js, I am trying to apply a background image to the entire content section: <v-content> <v-img src="https://picsum.photos/id/11/500/300" > <v-container justify-center fill-he ...

Duplicate the LI element in a way that it is inserted after the original LI instead of at the end

I am looking for a way to clone an item immediately after clicking on it instead of cloning it at the end of the list. Currently, it always clones to the END and adds it after the last LI in the list. Here is a link to the jsFiddle I created jsfiddle test ...

The div smoothly descended from the top of the page to the center under the control of jQuery

I am trying to implement a feature where a div slides down from the top of the page to the center when a button is clicked. However, my current code seems to be causing the div to slide from the bottom instead of the top. Ideally, I want the div to slide ...

When you click on the Admin Panel Side menu, the page refreshes instead of expanding the menu item

I have encountered a strange problem with the AdminLTE admin panel template that I am using in my Angular 11 application. Everything is loading fine with the menu items, but when I click on an item, instead of expanding the group, the page refreshes. Here ...

What is the best way to associate multiple references to a model within a nested document?

I am facing a challenge with populating a large nested document. var PortfolioSchema = new Schema({ bonds : { percentage : Number, USA : { percentage : Number, ...

What is the best way to modify a current state object without causing an endless loop of redirects?

const useCase = (argument) => { const [value, setValue] React.useState(argument) React.useEffect(() => setValue({...value ...argument), [argument, value, setValue]) } The above code is currently causing an infinite loop due to setting the stat ...

Should reports be created in Angular or Node? Is it better to generate HTML on the client side or server side

I have a daunting task ahead of me - creating 18 intricate reports filled with vast amounts of data for both print and PDF formats. These reports, however, do not require any user interaction. Currently, my process involves the following: The index.html ...

Placing a div on top of a link renders the link unusable

I am facing a situation and require assistance (related to HTML/CSS/JS) I currently have a div containing an image (occupying the entire div space) such that when hovered over, another div with an image is displayed on top (the second div is semi-transpar ...