JoHksi JoHksi - 1 year ago 96
AngularJS Question

Showing an image or text for few seconds using javascript

I am building a web app: front-end in Angular and back-end in Rails.
When users are done with filling out the application, they need to press "save" button to save the data.

Right now, when the user clicks the button, there is currently no feedback. When the button is clicked, I wanna show either text or image which says "Data Saved" for 2 seconds.

I would like to add code, but I have no idea how to even start with this. If anyone knows how to do this with Angular or Javascript, please let me know!

Answer Source

You've given very little to go on but generally:

JS (make sure to load $timeout and $scope as dependencies into controller):

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

    $scope.isVisible = true;

HTML (ID's aren't needed at all, just to point out what's what):

<div ng-show="isVisible" id="saveConfirmImg"></div>
<button ng-click="showImage()" id="saveButton"></button>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download