Conceal the Angular Bootstrap modal instead of shutting it down

I am utilizing Angular Bootstrap Modal to launch multiple modals, including a video player.

http://angular-ui.github.io/bootstrap/#/modal

My goal is to maintain the video's current position even when the modal is closed. This way, when I reopen the same modal, I can resume watching the video from where I left off.

In order to achieve this, I must:

  1. Create a separate instance for each modal

  2. Instead of using close(), I should hide() the modal. By doing so, the DOM elements remain intact and the video player does not need to be re-created.

I'm looking for an elegant solution since the Bootstrap modal does not have a hide feature. Is it advisable to use jQuery to show/hide the .modal-backdrop and .modal classes?

Answer №1

Extracted from a discussion on maintaining Angular Bootstrap modals upon closure:

Consider abstracting the modal state into its own service. This way, the modal controller can initialize the view state using the service.

For example, create a service:

.factory('ModalStateService', function(){
    var state = {
        someValue: 'something'
    };

    return {
        getState: function() { return state; }
    };
});

In your controller:

.controller('ModalCtrl', function($scope, ModalStateService){
    $scope.viewState = ModalStateService.getState();
});

In your modal content view:

 <span>{{viewState.someValue}}</span>

If you update someValue within your modal, like through an input, the service state will be updated. This ensures that the state persists even when the modal is created and destroyed.

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

Complete guide to Angular currency handling

How can I display a full currency value using Angular.js? <input class="receiptFrom" type="text" ng-model="receiptFrom"></input> <label>{{ receiptValue | currency }}</label> Currently, when I input 1000, it prints as $1,000.00. ...

Issue in Firefox: Footer is wrapping around the main content

Hey, I've been dealing with a pesky bug that just won't go away. We're currently working on a redesign for www.petpoint.com - The footer looks perfectly fine in every browser except for Firefox. It gets all jumbled up for some reason. I&a ...

"Debugging a simple demonstration showcasing NodeJS, AngularJS, and Express

Currently, I am following an online tutorial to learn a new concept. I have reached the part where I need to display data using HTTP GET from the controller, while the sample data is stored in the server file. I managed to fetch the data from the controlle ...

How can I implement jQuery autocomplete with customized settings?

In my Drupal project, I am looking to implement jQuery's auto complete feature to search for nodes based on their titles. I am having trouble finding examples that align with my specific requirements: The URL structure should be: /api/node/title/{wh ...

The element.find() function is experiencing issues when utilizing a templateUrl within a directive

My aim is to apply focus on an input field using a custom directive within a form. Initially, everything was functioning correctly when utilizing the template property in the directive. However, upon transferring the template into a separate HTML file usin ...

Arrange records in ascending order by phone number when multiple are returned on the same date

Currently, I am working on an Angular application that is designed to keep track of tuxedo rentals. The main feature of the app is a table that displays information from an array stored in the controller. The initial task I completed was listing the items ...

Having trouble retrieving mobiscroll instance in Angular with Ionic

I'm facing an issue with accessing the instance of my mobiscroll widget in Angular 4 with Ionic Framework. Despite following all the correct steps, the actual widget won't get selected. Below is the code for the widget: <mbsc-widget [options ...

Are there any instances of a race condition present in the following?

In the express server code snippet provided, there is a common object that is being manipulated in three different RESTful endpoints. Given that all HTTP requests in Node.js are asynchronous, it's possible to have simultaneous PUT and GET requests occ ...

Controlling the window opener; Inserting text into an element in the parent window

A pop-up window allows users to select files, then displays the selected image's URL. However, I need to take additional steps beyond that. I am seeking a method to input the URL into an input element on the parent window. window.opener.document.wri ...

Stop the change event from occurring on a textarea when the user clicks on an external cancel button

In a particular scenario, there is a textarea with an autosave feature triggered by the change event. When the textarea is focused on, Save and Cancel buttons appear at the bottom, providing users with options in case they prefer not to simply click outsid ...

Tips for exchanging JSON data between HTML and PHP using jQuery Ajax?

Hello there! I am just starting to learn PHP and jQuery, and I have been experimenting with some code to understand how things work. However, I seem to be having issues with sending data back and forth between my webpage and the PHP file on the server. Her ...

What is the best way to insert a newline in a shell_exec command in PHP

I need assistance with executing a node.js file using PHP. My goal is to achieve the following in PHP: C:proj> node main.js text="This is some text. >> some more text in next line" This is my PHP script: shell_exec('node C:\pr ...

An issue in D3.js where the chart bars are not properly synced with the x-axis labels

Currently delving into the world of d3.js for the first time. In our project, we needed to adjust the width of each bar from .attr('width', xScale.rangeBand()) line 46 to .attr('width', '10') line 50 After making this cha ...

In TypeScript, the catch block does not get triggered

I created a custom pipe in Angular that is supposed to format passed parameters to date format. The pipe contains a try-catch block to handle any errors, but surprisingly the catch block never seems to be executed even when an invalid date is passed. impo ...

The modal box should adjust its height to perfectly accommodate the content within

I'm in the process of developing a straightforward modal (popup) window, using as few lines of code as possible... just the basics. The modal has a maximum width of 650px and its height adjusts to fit the content. In case the content exceeds the avai ...

Tips on separating/callback functions based on earlier variables

Breaking Down Callback Functions Based on Previous Variables I am trying to figure out how to efficiently break down callback functions that depend on variables defined earlier in the code. Currently, my code resembles a "callback hell" due to my lack of ...

Issue with displaying options in Angular2 v2.4.9 HTML select element

Ever since I made the transition from AngularJS to Angular2, I've been facing a peculiar issue. The select element's options data is fetched from a Solr query, which always returns a 200 response with the data in a timely manner. However, the pr ...

Unable to prevent Protractor from showing file download prompt

Challenge Currently, I'm facing an issue with downloading a file where the "Save as..." dialog pops up when triggering the download. Although I found a potential solution on this Stack Overflow thread, it doesn't seem to be effective in my case. ...

Utilize Angular JS to dynamically load a personalized directive that aligns with the scope of the

I am looking to create a reusable tabbed element that can dynamically load custom directives based on the active tab. Essentially, I want a directive within a directive. So far, I have successfully implemented the tab wrapper and functionality to update $ ...

Using maxDate in Material UI DatePicker Component to set a maximum date limit

I'm having a tough time getting the maxDate property to function properly on the Material UI DatePicker component. It should disable dates after the specified maxDate. In my situation, I needed to set the maxDate to +60 days from the current Date(), ...