Open In App

How to make alert using Angular UI Bootstrap ?

Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will see how to make alerts using Angular UI bootstrap. Angular UI Bootstrap is an Angular JS framework created by Angular UI developers for providing better UI which can be used easily.

Alerts directive is used for generating alerts from static and dynamic model data.

Syntax:

<div uib-alert>alert</div>

Download AngularUI from the link:

https://angular-ui.github.io/bootstrap

 

Approach: 

  • First, add Angular UI bootstrap scripts needed for your project.

<script src=”https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.js”></script>
<script src=”https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular-animate.js”></script>
<script src=”https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular-sanitize.js”></script>
<script src=”https://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-2.5.0.js”></script>

  • Make div with Alert’s UIBootStrap classes which will make the UI look for the alert.
  • Now make different types of Alert using those classes and run the code.

Example:

HTML




<!DOCTYPE html>
<html ng-app="gfg">
  
<head>
  
    <!-- Adding CDN scripts required for our page -->
    <script src=
    </script>
    <script src=
    </script>
    <script src=
    </script>
    <script src=
    </script>
  
    <link href=
        rel="stylesheet">
  
    <script>
  
        // Adding Modules
        angular.module('gfg', ['ngAnimate', 'ngSanitize', 'ui.bootstrap']);
        angular.module('gfg').controller('Alert', function ($scope) {
        });
    </script>
</head>
  
<body>
    <div ng-controller="Alert">
          
        <!-- Making a simple class using uib-alert -->
        <div uib-alert style="background-color:green;color:white">
            A Simple Alert
        </div>
  
        <!-- Making a Warning Alert -->
        <div uib-alert ng-class="'alert-warning'">Warning Alert</div>
  
        <!-- Making a Danger Alert -->
        <div uib-alert ng-class="'alert-danger'">Danger Alert</div>
  
        <!-- Making a Success Alert -->
        <div uib-alert ng-class="'alert-success'">Success Alert</div>
    </div>
</body>
  
</html>


Output:

Reference: https://angular-ui.github.io/bootstrap/#!#alert



Last Updated : 06 Jun, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads