Changing the content inside a modal once it has been opened in AngularUI Bootstrap

Can anyone help me understand how to update the content within a modal once it's been opened? I need to trigger a modal when a specific event from a websocket occurs.

Following that event, I receive status updates and wish to replace the modal's current content with those statuses.

This is the snippet of code I use to open a modal:

var modalInstance = $uibModal.open({
    animation: true,
    template: r.message.description,
    windowTemplateUrl: 'modal.html',
    controller: 'ModalController',
    backdrop: true,
    size: 'lg',
    resolve: {}
});

The content of modal.html is as follows:

<script type="text/ng-template" id="modal.html">
      <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title">Document Reader</h4>
      </div>
      <div class="modal-body" uib-modal-transclude>
      </div>
      <div class="modal-footer">
      </div>
    </div>
  </div>
</script>

The variable r.message.description holds a string obtained from the websocket. This is what needs to be replaced within the modal.

Answer №1

Appreciate the responses, I experimented with both suggestions but ultimately decided to utilize events for transferring data between controllers in this specific scenario.

Within the MainController, I am executing:

$rootScope.$broadcast("dataTransferred", r.message);

Meanwhile, in the ModalController, I have set up an event listener:

$scope.$on("dataTransferred", function(evt, data) {
    $scope.result = data;
});

Answer №2

Check out this sample plunker I created to demonstrate how to send data to a modal.

By using resolve, you can inject the map into your designated ModalController. You can either write it directly in the resolve or make use of angular.copy for cleaner code (like I have done).

Replace r.message.description with $scope.name and call your controller (ensure it is a function) with an additional item (use dependency injection for minification). This item allows you to pass data to the modal through inheritance from the resolve.

Answer №3

Follow this method to display a static template:

template: '<div ng-bind-html="myScopeVar"></div>',
resolve: {
    eventTemplate: function(){
       return r.message.description;
    }
}

Then, handle "myScopeVar" within the modal controller.

If your template includes an Angular directive, create a custom directive to compile it.

template: '<div compile-template="myScopeVar"></div>'

To create the compile-template directive, utilize the $compile service.

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

Utilizing TinyMCE: Transferring HTML content to a PHP or JS webpage

Hello there, I've been struggling to find a solution for transferring the data from the TinyMCE text editor (a plugin of textarea) to a different page. AJAX didn't work out for me. Is there a reliable method to extract the HTML value and send it ...

Oops! An uncaught exception error occurred because the primordials were not defined

I used npm to install the package called aws-s3-zipper, but now I am encountering an error. This is the code snippet causing the issue: AWS = require("aws-sdk"); var S3Zipper = require("aws-s3-zipper"); function zipFolderOnS3() { var zipper = new S3 ...

What may be causing the lag in the translation within ThreeJS?

Just started diving into ThreeJS and discovering its capabilities. Playing around with a simple example of creating a white dot and applying a basic translation. let dotGeometry = new THREE.Geometry(); let dotMaterial = new THREE.PointsMaterial({ size: ...

ReactNative: When attempting to navigate, a TypeError occurred - this.props.navigation.navigate is not a function

It's confusing to see how this issue is occurring, even though all props have been properly typed. The goal is to pass the navigator to the bottom bar component in order to navigate onPress. Initially, I define the props interface: export interface B ...

Utilizing Angular.js to Retrieve JSON Data Using the HTTP Response Interceptor

When it comes to handling HTTP requests and responses, I have a setup that involves sending requests with a 404 status code while also intercepting them in an Angular Service. res.status(404).send({message: 'O Captain! My Captain!'}); In my Ang ...

The Jasmine spy named spyOnevent returned an undefined value

const spyEvent = spyOnEvent('#BackYoyButton', 'click'); $('#BackYoyButton').trigger( "click" ); expect('click').toHaveBeenTriggeredOn($('#BackYoyButton')); expect(spyEvent).toHaveBee ...

Is there a way to use regular expressions to search for class names within nested div elements?

I'm struggling to find nested divs like these in my document object model (DOM) <div class="two-columns some-other-class"> <div class="two-columns some-other-class"> </div> </div> I attempted to search for neste ...

Display problem with Backbone view

I'm having trouble loading views on my page while using underscore for templating. I've tried navigating to the page and loading the view in the initialize function, but neither approach has worked. The majority of this code is from an example. ...

Tips for updating or refreshing a table in Rails using Actioncable

My Action Cable functionality is performing well, displaying an alert with the data content (although this alert appears on all pages). Here's the scenario: a user with the role of ADMIN can access a URL (http://localhost:3000/ventas/) that contains ...

Strict mode does not allow duplicate data properties in object literals within JavaScript

Challenge Description I am facing an issue with handling an optional variable called ByteRange. To accommodate this, I included 2 different URLs in the $resource. Upon doing so, I encountered the following error: Message: Error in parsing: "tools/tes ...

Utilizing Vue 2 and Vue 3 simultaneously: maximizing the potential of Vue JS in your project

I need to access a function that is defined in a JS class component. To use this function in the composition API, I need to: setup(props) { const {errorMessages, handleInput, setFieldData} = Validator.register(props); // function to use return { ...

Encountering difficulties with uploading files and images in a Node.js environment

Currently, I am learning node js and express js on Tutorial Point. In the course, I attempted to upload a document but encountered an error that says "Cannot read property 'file' of undefined." Can someone please assist me in resolving this issue ...

Learn the process of utilizing JavaScript/Node.js to dynamically upload images onto a webpage directly from a database

Currently, I am developing a web application and building a user profile page where I aim to showcase user information along with a profile picture. Working with node/express/jade stack, I have a javascript file that manages loading the appropriate jade vi ...

Online portal for showcasing merchandise

I am currently working on developing a compact web store using .net. This web store solution will house multiple "webshops" all utilizing the same server. My main concern is regarding performance issues when it comes to using jQuery Ajax calls to retrieve ...

Utilizing BBC gelui within Joomla 3.0 for seamless integration

I am currently using Joomla! 3.0 with the Joomlashape Helix template and I am following a tutorial. You can check out the tutorial here. The tutorial mentions that I need to download RequireJS. Can anyone confirm if RequireJS is compatible with Joomla 3 ...

Is there a quicker method than using document.getElementById('element-id').innerHTML to retrieve content?

Currently, I am developing a user-friendly step-by-step wizard for my website to gather information about custom orders. Utilizing JavaScript, I have been tasked with updating the content of each "page" using the document.getElementById('element-id&ap ...

Angular JS Error: Unable to find the registered controller named 'myCtrl1' due to [$controller:ctrlreg] error

This is a snippet of Angular code that I've been working on, but when I try to run it, I encounter the following error message: Module 'myApp1' is not available! You either misspelled the module name or forgot to load it. Here's the c ...

The property 'get' cannot be accessed because the axios module of vue__WEBPACK_IMPORTED_MODULE_0__ is undefined

Having some trouble with Vue and Axios - encountering the following error message: [Vue warn]: Error in created hook: "TypeError: can't access property "get", vue__WEBPACK_IMPORTED_MODULE_0__.default.axios is undefined" Here's the code snippet: ...

"Why does the form.submit() function fail in IE9 when the form is in an iframe and the user is coming from Gmail

I have recently developed a function within my CodeIgniter framework that allows me to send emails with a backlink to my site. The link directs users to a page on my website that includes an iframe. Within this iframe, I have implemented a file input form ...

Slowly introduce a sequence of divs, then smoothly fade out the div that came before

After successfully using jQuery to create a smooth fade-in effect for a series of divs, I am now looking to incorporate a fade-out transition for the previous div. My plan is to include a fade out function as a callback within the existing fade in function ...