Content briefly appears and then vanishes with the use of ng-if

On my webpage, I have content that is enclosed in an ng-if directive as shown below:

<div ng-if="ShowMessgae" class="text-danger">
    <p>
        <strong>
            Message displayed to User
        </strong>
    </p>
</div>

Within my AngularJS controller, I have the following setup:

function MyController($scope, $q, notifyHelper) {
    openAjaxLoaderGif();

    $scope.ShowMessgae = false;

    MyService.getVarsFromSession().then(function (result) {
       // code omitted for brevity
       if(some coditional) {
        $scope.ShowMessgae = true;
       }

        }, function (data, failReason, headers) {
            notifyHelper.error("Error has occurred - try again");
        })
    })
    .finally(function () {
        closeAjaxLoaderGif();
    });
};

I am initializing the ShowMessage variable to false and it only becomes true under certain conditions.Usually, ShowMessage will be false. However, when the page loads, the "Message displayed to User" text briefly appears and then disappears. Is there something wrong causing this flicker effect?

Answer №1

The reason behind this occurrence is that the content gets displayed by AngularJS until it recognizes that ShowMessgae is set to false, and then proceeds to hide it.

To avoid displaying the content altogether until Angular is able to determine whether ShowMessgae is either true or false, it is recommended to utilize ng-cloak. This will ensure that the content remains hidden until AngularJS has established the value of ShowMessgae. Subsequently, at this juncture, the framework will be prepared to display (or not) the content according to the value of ShowMessgae

<div ng-if="ShowMessgae" class="text-danger" ng-cloak>
    <p>
        <strong>
            Message shown to User
        </strong>
    </p>
</div>

Answer №2

To include the ng-cloak attribute, follow these steps:

<div ng-if="ShowMessgae" class="text-danger" ng-cloak>
   <p>
     <strong>
         Message shown to User
     </strong>
   </p>
 </div>

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

Join the Observable in Angular2 Newsletter for the latest updates and tips

One of my functions stores the previous URL address. prevId () { let name, id, lat, lng; this.router.events .filter(event => event instanceof NavigationEnd) .subscribe(e => { console.log('prev:', this.previo ...

Is it possible to create an input field exclusively for tags using only CSS?

I am currently facing some limitations with a website I am managing. Unfortunately, I do not have the ability to incorporate additional libraries such as custom jQuery or JavaScript scripts. My goal is to customize an input field for tags so that when us ...

What is the best way to connect a nested Vuex object to a Vue.js property within the Tiptap text editor?

I'm attempting to connect the nested Vuex state object to the editor property of the tiptap's editor-content component. The structure of the state is as follows: <template> <table :style="{ backgroundColor: element.options.ba ...

Leverage the Power of Two AngularJS Factories

Can I efficiently use two Factories in AngularJS by calling one from the other? Here's the Scenario: I have a Factory that returns an Array. This Factory is responsible for checking if the data to populate this Array already exists in local SQL Stor ...

VueJS does not show a component if it is contained within a v-if or v-show directive

My goal is to show a component when the 'Add Patient' button is clicked using a v-if directive: // within <template></template> <button type="button" class="btn btn-info" @click="showPatientForm">Ad ...

Managing pop-up modals through a controller and service

As a newcomer to AngularJS (version 1.6), I have set myself a small challenge - to create a new popup modal that appears when clicking an "edit" button, allowing users to edit certain text-boxes. I am struggling to figure out how to properly integrate all ...

Reinitializing a form with jQuery validation inside a modal box

While utilizing jQuery Validate in a form within a jQuery dialog, I am encountering an issue. Upon closing the dialog, I aim to clear all form fields and reset any fields with error feedback displayed. Although the fields are being reset to blank as expec ...

Using Promises Across Multiple Files in NodeJs

Initially, I had a file containing a promise that worked perfectly. However, realizing the need to reuse these functions frequently, I decided to create a new file to hold the function and used module.export for universal access. When I log crop_inventory ...

Having trouble retrieving an object through a GET request in Node.js with Express

Currently, I am going through a tutorial on Node.js by Traversy Media and I have encountered an issue that has me stumped. The problem arises when I attempt to retrieve the response of a single object from an array of objects using the following code: app ...

Organize information in a React table following a predetermined sequence, not based on alphabetical order

As a beginner with React, I'm looking to sort my data by the column "Status" in a specific order (B, A, C) and vice versa, not alphabetically. The data structure looks like this: export interface Delivery { id: number; name: string; amount: num ...

Firefox returns a "null" error when attempting to access the Vimeo API, whereas there are no errors reported when accessing the YouTube API or when

I tried researching this issue on multiple platforms, including Google and other forums, but I am still unable to resolve it. I recently transitioned from a proxy request approach (using AJAX to communicate with a server-side script that then interacts wit ...

Developing a Secondary User within Meteor.JS after Establishing the Primary User

Is it possible to automatically create a secondary user upon registration of the primary user using a form generated with the useraccounts:core package? An issue arises when attempting to run Accounts.createUser within Accounts.onCreateUser, resulting in ...

React's componentDidUpdate being triggered before prop change occurs

I am working with the CryptoHistoricGraph component in my app.js file. I have passed this.state.coinPrices as a prop for this element. import React from 'react'; import axios from 'axios'; import CryptoSelect from './components/cry ...

Accessing the AngularJS app through a classic login interface

Embarking on a new project, I have decided to create a straightforward web application using Python Flask for the API and AngularJS for the frontend, both being served by Nginx. The secure api can be accessed at http://site/api/. In my quest for authentic ...

Clickable list element with a button on top

Within my web application, there is a list displaying options for the user. Each 'li' element within this list is clickable, allowing the user to navigate to their selected option. Additionally, every 'li' element contains two buttons - ...

"Encountering issues with createReadStream function when handling large files, performance is significantly

Currently, I am utilizing the DropBox API for file uploads. The process involves several steps: Begin by uploading the file from a form to a local directory on the server. Read the file from the local directory using fs.createReadStream. Transfer the fil ...

Using Node.js to retrieve child processes associated with a daemon and terminate them

I am attempting to create a node application that allows me to send the command kill -9 to all child processes of a single daemon. Just to clarify, there is one daemon running on our server. Upon startup, it initiates a process for communicating with clie ...

How to position an image on top of each printed page using HTML/CSS (SCSS)

I've created a simple and small webpage that looks like this: https://i.sstatic.net/R7Ajz.png Everything is perfect in the browser, with all the styles (margin, padding, etc.) just as I want it. However, my issue lies in the print view of the page. ...

Filtering in AngularJs with multiple select options

I am curious about how to create a filter with multiple options. I have a grid with specific settings and column definitions as shown below: $scope.gridOptions = { enableHorizontalScrollbar: 1, enableFiltering: true, p ...

Conceal overflow content within a Bootstrap btn-group using CSS styling

Suppose I have a table like the one below: /* CSS Styles for the table */ table.my { width: 600px; } table.my > tr { height: 40px; overflow: hidden; } .tag { background: #b8b8b8; padding ...