How can I dismiss a modal in Angular UI Bootstrap without using a controller?

Exploring AngularJS and diving into the world of Angular UI Modal found at: http://angular-ui.github.io/bootstrap/.

Searching for a way to create a basic modal with just one close button without needing a separate controller. Is there a simple script like ng-click event in the modal template that can achieve this? Maybe something like this.close()...

The desired outcome should resemble this:

Template:

<div class="modal-header">
  <h3>Modal header</h3>
</div>
<div class="modal-body">
 <h4>Just something random here</h4>
</div>
<div class="modal-footer">
    <button class="btn btn-primary" ng-click="this.close()">OK</button>
</div>

Page controller:

  $scope.openModal = function() {
    $uibModal.open({
      templateUrl: "modalContent.html",
      // aiming for simplicity, hence avoiding an additional controller
      //controller: "ModalContentCtrl",
      size: '',
      backdrop: 'static',
      keyboard: false
    });
  };

Answer №1

Quoting from the official documentation:

The scope linked with the content of the modal is enhanced by:

$close(result) (Type: function) - A function that allows for the closure of a modal along with passing a result.

$dismiss(reason) (Type: function) - A function that enables the dismissal of a modal, providing a reason.

These functions facilitate the closing of a modal window without requiring a specific controller to be created.

Thus, the following code snippet demonstrates this functionality:

<div class="modal-header">
  <h3>Modal header</h3>
</div>
<div class="modal-body">
 <h4>Just some random content here</h4>
</div>
<div class="modal-footer">
    <button class="btn btn-primary" ng-click="$close()">OK</button>
</div>

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

React Big Calendar - Creating a personalized property for a unique perspective

My React Big Calendar library has a custom view for the year. <Calendar localizer={localizer} events={events || []} startAccessor="start" endAccessor="end" defaultView="year" views={{ year: YearView }} c ...

Tips for utilizing nested ng-repeat efficiently

Can anyone help me with creating a nested ng-repeat? I currently have code that is not nested and prints all subjects first followed by student names. However, I need to print students for each subject. How can I convert it to a nested ng-repeat? <tr& ...

JS Code for Optimal Viewing on Mobile Devices

I'm struggling with creating 3 image columns in 2 columns on mobile. It seems like there is a JS issue related to the minslide:3 and maxslide:3 conditions... When viewed on mobile, it's displaying 3 slides instead of 2. How can I adjust it to sh ...

What is the reason behind why create-react-app generates the App.js file as a functional component?

Learning React has been quite fascinating for me. I recently used npx create-react-app my-project and noticed that the App.js file was created as a functional component, instead of a class component like in previous versions. After digging around, I stumbl ...

The issue of a blank first page occurring when attempting to print the contents of an

I am encountering an issue with printing a webpage that contains three images. When printing directly from Internet Explorer, it correctly prints three pages, one for each image. However, when loading the same page within an iframe and printing the iframe ...

I am looking for a way to showcase the form value either in the address bar or transfer it to another page using JavaScript. Can

Currently facing a challenge with a form where I need to input the name and email, redirect these values to another page, and display them in the address bar using only JavaScript. Take a look at the form here: View Form Code snippet for the form: <f ...

Transforming a form containing recurring elements into JSON

Sorry if this topic has already been discussed, I wasn't able to locate any information I currently have an html form structured like so: <form> <div> First Name <input name="FirstName" type="text"> Age <input name="Age" t ...

The submit button is not reading the JavaScript file for validation and instead goes directly to my PHP file

**Hello, I'm new to Stack Overflow. My submit button is not reading the JavaScript file I created; instead, it goes straight to the PHP file without validating the input fields first in the JavaScript file. I've been stuck here for hours and can& ...

Guidelines for setting the Id and value for a Hidden field

I am working with a gridview that has a few rows and columns, each containing ListBox Controls. Markup: <asp:GridView ID="gvDataEntry" runat="server" AutoGenerateColumns="False" <Columns> <ItemTemplate> <asp:ListBox ID="lst ...

The dropdown menu is malfunctioning

Currently, I am in the process of creating a simple web application that involves the use of two JavaScript libraries, dat.gui, and three.js. One issue that I am encountering is that the drop-down menu appears to be locked and I am unable to access it. / ...

Are you experimenting with an AngularJS directive?

What would be your approach to testing this angular testing directive? $scope.cancel = function () { $('#pp_bsktexit').modal('show'); }; Something similar to this can be tested, but it doesn't seem too complex: var ...

Setting the default TAB in a specific Menu Tab within the Menu Bar

I'm encountering some issues with this code. Specifically, the menu bar JavaScript is automatically clicking on the Second TAB instead of the First TAB when run. JS CODE. var dolphintabs = { subcontainers: [], last_accessed_tab: null, ...

Tips for optimizing images for mobile screens and ensuring responsiveness

I'm trying to ensure that my image only loads on mobile screens and remains responsive so it doesn't stretch. However, the code I've written isn't working as expected. Currently, the image takes up the whole browser window and appears o ...

Guide on choosing a specific div element from a different page using AJAX

I have a Social Media platform with posts, and I am trying to display the newest ones using JavaScript (JS) and AJAX. I attempted to reload my page using AJAX and insert it into a div element, but now the entire website is loading within that div element, ...

Encountering an unexpected or invalid token in line 1 after reinstallation of Windows can be a frustrating experience

Yesterday, my JavaScript file was running smoothly. However, after reinstalling Windows and Node, I'm encountering an error when trying to run the same JavaScript file today. $ node index.js C:\Users\<user-name>\Google Drive&bsol ...

What steps do I need to take to ensure that this Regex pattern only recognizes percentages?

I am attempting to create a specific scenario where I can restrict my string to three digits, followed by a dot and two optional digits after the dot. For example: 100.00 1 10.56 31.5 I've developed a regex pattern that allows me to filter out any ...

What causes the cancel button to add spaces and create a line break in the textarea field?

Whenever I click the "cancel" button, the textarea inexplicably receives 26 spaces before any existing text and a carriage return after it. This issue occurs when the cancel button is styled in the traditional HTML manner: <button type="reset" name="re ...

Including a new initial parameter before implementing the existing arguments

I have been experimenting with using the map function to apply a set of functions in my code: function runWaterfall(consumer, fns, cb) { fns = fns.map(function(fn) { return function() { fn(consumer, arguments); } }); ...

Creating personalized URLs for RESTful API with Node.js and MongoDB

Within my nodejs api, I have a mongoose schema set up as follows: var profileschema = new mongoose.Schema({ name: { type: String }, surname: { type: String }, id: { type: String } }); Additionally, there is a rout ...

Creating a Navigation Bar with AngularJS

Can someone assist me in creating a navigation bar with N elements? This is the directive I currently have: angular.module('tool') .directive('navigation', [function () { return { restrict: 'E', controlle ...