Home Web Front-end JS Tutorial Detailed example of how to use ngModal modal box in AngularJS

Detailed example of how to use ngModal modal box in AngularJS

May 28, 2017 am 10:39 AM

This article mainly introduces the example of using ngModal modal box in AngularJS. The editor thinks it is quite good. Now I will share it with you and give it as a reference. Let’s follow the editor and take a look.

Using modal boxes in AngularJS requires referencing files:

  1. angular.js 1.5.5

  2. ui.bootstrap-tpls.js 0.11.2

  3. bootstrap.css 3.3.7

It should be noted that the versions must be consistent. Higher versions do not support this method and an error will occur.

Write the content of the modal box that needs to pop up in the script tag and indicate Attribute, put it in the page

<script type="text/ng-template" id="modal.html"> 
<p>
  <p class="modal-header">
    <h3 class="modal-title" align="center">
      标题信息
    </h3>
  </p>
  <p class="modal-body">
    <p align="center">
      模态框内容
    </p>
  </p>
  <p class="modal-footer">
    <button class="btn btn-primary" ng-click="ok()">
      确认
    </button>
    <button class="btn btn-warning" ng-click="cancel()">
      退出
    </button>
  </p>
</p>
</script>
Copy after login

Inject modal box in App and Controller

var app = angular.module(&#39;app&#39;, [&#39;ui.bootstrap&#39;]);
app.controller(&#39;modalController&#39;, function($scope, $rootScope,$modal) {
  $scope.openModel = function() {
      var modalInstance = $modal.open({
        templateUrl : &#39;modal.html&#39;,//script标签中定义的id
        controller : &#39;modalCtrl&#39;,//modal对应的Controller
        resolve : {
          data : function() {//data作为modal的controller传入的参数
             return data;//用于传递数据
          }
        }
      })
    }
}

//模态框对应的Controller
app.controller(&#39;modalCtrl&#39;, function($scope, $modalInstance, data) {
  $scope.data= data;

  //在这里处理要进行的操作  
  $scope.ok = function() {
    $modalInstance.close();
  };
  $scope.cancel = function() {
    $modalInstance.dismiss(&#39;cancel&#39;);
  }
});
Copy after login

AddEventTrigger display of modal box

<button ng-click="openModal()">打开模态框</button>
Copy after login

html




  ng-model模态框



<button ng-click="openModal()">打开模态框</button>








Copy after login

The above is the detailed content of Detailed example of how to use ngModal modal box in AngularJS. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

The latest 5 angularjs tutorials in 2022, from entry to mastery The latest 5 angularjs tutorials in 2022, from entry to mastery Jun 15, 2017 pm 05:50 PM

Javascript is a very unique language. It is unique in terms of the organization of the code, the programming paradigm of the code, and the object-oriented theory. The issue of whether Javascript is an object-oriented language that has been debated for a long time has obviously been There is an answer. However, even though Javascript has been dominant for twenty years, if you want to understand popular frameworks such as jQuery, Angularjs, and even React, just watch the "Black Horse Cloud Classroom JavaScript Advanced Framework Design Video Tutorial".

Use PHP and AngularJS to build a responsive website to provide a high-quality user experience Use PHP and AngularJS to build a responsive website to provide a high-quality user experience Jun 27, 2023 pm 07:37 PM

In today's information age, websites have become an important tool for people to obtain information and communicate. A responsive website can adapt to various devices and provide users with a high-quality experience, which has become a hot spot in modern website development. This article will introduce how to use PHP and AngularJS to build a responsive website to provide a high-quality user experience. Introduction to PHP PHP is an open source server-side programming language ideal for web development. PHP has many advantages, such as easy to learn, cross-platform, rich tool library, development efficiency

Build web applications using PHP and AngularJS Build web applications using PHP and AngularJS May 27, 2023 pm 08:10 PM

With the continuous development of the Internet, Web applications have become an important part of enterprise information construction and a necessary means of modernization work. In order to make web applications easy to develop, maintain and expand, developers need to choose a technical framework and programming language that suits their development needs. PHP and AngularJS are two very popular web development technologies. They are server-side and client-side solutions respectively. Their combined use can greatly improve the development efficiency and user experience of web applications. Advantages of PHPPHP

HTML, CSS, and jQuery: Build a beautiful modal HTML, CSS, and jQuery: Build a beautiful modal Oct 25, 2023 pm 12:03 PM

HTML, CSS and jQuery: Build a beautiful modal box Introduction: Pop-up windows or modal boxes are often used in web pages to display information and achieve interactive effects. This article will introduce how to use HTML, CSS and jQuery to build a beautiful modal box, with specific code examples. 1. HTML structure: First, we need to create an HTML structure to accommodate the modal box. The code looks like this: &lt;!DOCTYPEhtml&gt;&lt;html&gt;

How to use Vue to implement modal box effects How to use Vue to implement modal box effects Sep 22, 2023 am 10:36 AM

How to use Vue to implement modal box special effects With the development of Internet technology, modal boxes (Modal) are widely used in web design as a common interaction method. Modal boxes can be used to display pop-up windows, warnings, confirmations and other information to give users a better interactive experience. This article will introduce how to use the Vue framework to implement a simple modal box effect and provide specific code examples. The following are the steps to implement modal box effects: Create a Vue instance. First, we need to introduce the Vue CDN link in the HTML file and add it in Ja

How to implement dialog boxes and modal boxes in Vue? How to implement dialog boxes and modal boxes in Vue? Jun 25, 2023 am 09:26 AM

How to implement dialog boxes and modal boxes in Vue? With the continuous development and updating of front-end technology, the development of front-end pages has become more and more complex and diverse. Dialog boxes and modal boxes are elements that often appear in front-end pages and can help us achieve more flexible and diverse interactive effects. In Vue, there are many ways to implement dialog boxes and modal boxes. This article will introduce you to several common implementation methods. 1. Use Vue’s own components. Vue.js provides some built-in components, such as transition and tra.

Use PHP and AngularJS to develop an online file management platform to facilitate file management Use PHP and AngularJS to develop an online file management platform to facilitate file management Jun 27, 2023 pm 01:34 PM

With the popularity of the Internet, more and more people are using the network to transfer and share files. However, due to various reasons, using traditional methods such as FTP for file management cannot meet the needs of modern users. Therefore, establishing an easy-to-use, efficient, and secure online file management platform has become a trend. The online file management platform introduced in this article is based on PHP and AngularJS. It can easily perform file upload, download, edit, delete and other operations, and provides a series of powerful functions, such as file sharing, search,

Build a single-page web application using Flask and AngularJS Build a single-page web application using Flask and AngularJS Jun 17, 2023 am 08:49 AM

With the rapid development of Web technology, Single Page Web Application (SinglePage Application, SPA) has become an increasingly popular Web application model. Compared with traditional multi-page web applications, the biggest advantage of SPA is that the user experience is smoother, and the computing pressure on the server is also greatly reduced. In this article, we will introduce how to build a simple SPA using Flask and AngularJS. Flask is a lightweight Py

See all articles