ItSolutionStuff.com

How to Hide Div After Some Time in AngularJS?

By Hardik Savani • October 20, 2023
Angular

Sometimes we require to do like hide div or text or any tag after some time using AngularJS. In this example i am going to show you how to do it.

AngularJS have $timeout variable, $timeout variable through we can set specific time after hide. We can easily set time for hide or show. In this simple example you can see how it is works.

Bellow example you can see and run bellow file in your machine.

Example:

<!DOCTYPE html>

<html>

<head>

<title>Angularjs ng-hide div after few seconds</title>

<script src = "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>

</head>

<body>

<div ng-app = "mainApp" ng-controller = "myController">

<p ng-hide="isCheck" style="background:red;padding:5px;">{{ myText }}</p>

</div>


<script>

var mainApp = angular.module("mainApp", []);

mainApp.controller('myController', function($scope, $timeout) {

$scope.myText = "This is for example";

$scope.isCheck = false;


$timeout(function () { $scope.isCheck = true; }, 4000);

});

</script>


</body>

</html>

Tags: Angular
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

AngularJS Drag and Drop Table Rows Example with Demo

Read Now →

PHP AngularJS Add Remove Input Fields Dynamically Example

Read Now →

AngularJS Ajax Autocomplete Using Typeahead in PHP Example

Read Now →

AngularJS Scroll to a Specific Element using Anchorscroll

Read Now →

AngularJS Convert Comma Separated String to Array Example

Read Now →

AngularJS Image Upload with Preview Example

Read Now →

How to Call Function on Page Load in AngularJS?

Read Now →

AngularJS Tooltip using UI Bootstrap tpls HTML Example

Read Now →

AngularJS Simple Datepicker Directive Example Tutorial

Read Now →

How to Change Date Format using Date Filter in AngularJS?

Read Now →

AngularJS - How to Limit String Length using Filter?

Read Now →

AngularJS - How to Capitalize the First Letter of Word Example

Read Now →

How to Remove HTML Tags from String in AngularJS?

Read Now →

PHP AngularJS CRUD with Search and Pagination Tutorial

Read Now →