Displaying an image or text briefly using javascript

I am currently developing a web application, with the front-end being built in Angular and the back-end in Rails. Once users have completed filling out the application, they are required to click the "save" button to store the data.

Currently, when the user clicks the button, there is no visual feedback provided. I want to display text or an image saying "Data Saved" for 2 seconds after the button is clicked.

I would like to implement this feature, but I am unsure of where to begin. If anyone has experience with adding this functionality using Angular or JavaScript, please share your knowledge with me!

Answer №1

Although the information provided is limited, the following approach can be considered:

In JavaScript (ensure that $timeout and $scope are loaded as dependencies into the controller):

$scope.showImage = function() {
    $timeout(function() {
        $scope.isVisible = false;
    }, 2000);

    $scope.isVisible = true;
};

For HTML (IDs are not necessary, but included for clarity):

<div ng-show="isVisible" id="saveConfirmImg"></div>
<button ng-click="showImage()" id="saveButton"></button>

Answer №2

I'm sharing this much with you as there is no code visible:

<div ng-show="loading"></div>

$scope.loading = false;

$scope.onClick = function() {
    $scope.loading = true;
    saveData(data).then(function()) {
        $scope.loading = false;
    }
}

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

Clearly state the action of the form

I have utilized html, JavaScript, CSS, and JQuery to create a website template. Within this template, there is a file called contact.js that contains the ajax code for handling forms: $(function() { submitSuccess: function($form, event) { ...

How can I set the input tag to reset back to 1 when a certain event occurs?

I am currently developing an HTML Snakes And Ladders game. On the settings screen, there is an input field where users can select the size of the board. Depending on their choice, they will be able to choose a maximum number of snakes and ladders. For exa ...

Issue with menu display after clicking icon

On my website, I am trying to set up an icon that will display a menu bar for mobile users. I have written some JavaScript code for this functionality, but it's not working as expected. My approach involved creating an element called "Menu" and assign ...

Unable to utilize a variable from React Context for accessing the value within an object

I'm facing a peculiar yet seemingly straightforward issue. My object named vatRates is structured as follows: const vatRates = { "AD": 0.00, "CZ": 1.21, "RO": 1.19, "DE": 1.19, "RS": 0.00, ...

Using javascript to color in cells of a grid of "pixels"

I have a project similar to an Etch-a-Sketch in progress. The main challenge I am currently facing is how to gradually darken each cell of the grid with every pass of the mouse cursor, based on the opacity of the cell being hovered over. When the grid cell ...

Encountering an issue... invariant.js:42 Error: A `string` value was received instead of a function for the `onClick` listener

Currently, I am working on creating a form that allows users to build quizzes without any restrictions on the number of questions they must include. To achieve this, I plan to add an "add question" button at the bottom of the quiz form, allowing users to d ...

What is the best way to use appendChild within an AJAX get function to manipulate the DOM

I've been working on a code function where I try to append a list item (li) into the HTML received in 'msg', but it's not functioning properly. Any ideas why? function handleFileSelect(evt) { var files = evt.target.files; $(&ap ...

The color of the form button should switch when the user hovers over it with their mouse pointer

Here is my form with a custom button: <form action="login_form.php" method="POST" id="login_form"> Email <input name="email" type="text" size="25" placeholder="type your email"/> Password <input name="password" type="text" size ...

When the onClick event on one element triggers a change in another element within the

I apologize if the title is not clear. I have a React component with buttons and text, which I have used three times. My goal is for each button to display its respective text when clicked, while hiding the texts associated with the other buttons. While m ...

Oops! Looks like the maximum call stack size has been exceeded, resulting in a RangeError. Additionally, a warning from Vue has been triggered due to an error in the v-on handler related to

I am in the process of developing a student management system that provides me with a comprehensive list of students, their individual details, and a feature within the "StudentDetails" component that enables me to navigate to another component. Below are ...

The scrolling action triggered by el.scrollIntoViewIfNeeded() goes way past the top boundary

el.scrollIntoViewIfNeeded() function is used to scroll to element el if it's not within the visible browser area. Although it generally works well, I have encountered some issues when trying to use it with a fixed header. I have provided an example s ...

The Express Generator is having trouble detecting the routes within the users file when using app.use('/login', users)

Having used the express generator, I am facing confusion regarding why I cannot utilize the users.js routes file for my login routes. I have created the POST route below, and when I keep it in app.js, everything works smoothly. However, if I attempt to mo ...

Alignment customization in Exceljs for richText cells

"exceljs": "^3.9.0" In order to create a spreadsheet with cells containing two different values, each aligned differently (one left and one right), I am looking for a solution similar to the image shown in this screenshot: https://i.ss ...

development of MapLayers with rails and javascript

As a newcomer to RoR, I am encountering an issue that seems to be eluding me. I attempted to replicate the example application found on the mapLayers GitHub repository at https://github.com/pka/map_layers/wiki. However, all I see is the JavaScript code gen ...

Pulling a div from beneath numerous other divs

I have been attempting to create a test case for a web application we are developing and I am on the verge of finding a solution, but there is one final hurdle that has me puzzled... Our requirement is to enable div elements to be draggable (which is work ...

Tips on implementing smooth-scroll scrollLeft in Vue3 with JavaScript

Currently, I am in the process of creating a horizontal scroll menu for displaying images. The navigation functionality includes arrow buttons for scrolling: <template> <section id="artwork" class="artwork"> <div cl ...

Changing a button's value on click using PhoneGap

I've been working with phonegap and came across an issue with my buttons setup like this: <input id="my_button" type="button" onclick="my_function();"/> The goal is to capture the click event and change the button's value, my_function ( ...

Transform a C# DateTime object into a JavaScript date format

In my Javascript function, I am handling a C# DateTime received from MVC. If the date is null, it should return "-", and if it's a valid date, it should be returned in the formatted date. IMPORTANT: The date must be sent in the specified format from ...

Encountered a RunTime Error when attempting to Lazy Load a module

When attempting to lazy-load a component separately, an unexpected run-time error is occurring. This issue is specifically related to writing loadChildren within the routing module of another component in Angular 6. Any assistance with resolving this error ...

Deno-test encounters an undetermined AssertionError

Below is a test case example for Deno that I am using: Deno.test("Run LS", () => { const cmd = Deno.run({ cmd: ["ls"], stdout: "piped", stderr: "piped", }); let status: Deno.ProcessStatus, stdou ...