The Angular modal service is failing to show up on the screen

I am having trouble implementing the angular modal service in my web application. When I click on the button, the modal does not appear. Can someone help me figure out what I am doing wrong?

Builder View

<div ng-controller="BuilderController as vm">
    <button type="button" class="btn btn-success" ng-click="vm.showExportModal()">Export</button>
</div>

Builder Controller

angular.module('myWebApp')
  .controller('BuilderController', function ($scope, BuilderService) {    
    var vm = this;

    vm.showExportModal = function() {
      BuilderService.showExportModal();
    }; 
  });

Builder Service

angular.module('myWebApp')
  .service('BuilderService', function (ModalService) {

    var builderService = {
      showExportModal: showExportModal
    };
    return builderService;

    function showExportModal() {
      ModalService.showModal({
        template: "<div>Fry lives in {{futurama.city}}</div>",
        controller: function() {
          this.city = "New New York";
        },
        controllerAs : "futurama"
      })
    };

  });

Answer №1

It appears to be functioning correctly within this code snippet; my suggestion would be to verify that you have injected it as a dependency in your application.

Additionally, please ensure that you have the appropriate modal template in place to show a modal instead of the current template linked to the directive.

angular.module('myWebApp', ['angularModalService']);

angular.module('myWebApp')
  .controller('BuilderController', function($scope, BuilderService) {
    var vm = this;

    vm.showExportModal = function() {
      BuilderService.showExportModal();
    };
  });

angular.module('myWebApp')
  .service('BuilderService', function(ModalService) {

    var builderService = {
      showExportModal: showExportModal
    };
    return builderService;

    function showExportModal() {
      ModalService.showModal({
        template: "<div>Fry lives in {{futurama.city}}</div>",
        controller: function() {
          this.city = "New New York";
        },
        controllerAs: "futurama"
      })
    };

  });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<script src="http://dwmkerr.github.io/angular-modal-service/angular-
modal-service.js"></script>

<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">

<div ng-app="myWebApp">
  <div ng-controller="BuilderController as vm">
    <button type="button" class="btn btn-success" ng-click="vm.showExportModal()">Export</button>
  </div>
</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

Two separate occurrences hold identical values

I'm encountering an issue where instantiating a class two times results in the second instance retaining parameters from the first instance. Here's a simple example: var Test = function() {}; Test.prototype = { bonjour: null, hello: { h ...

Learn how to retrieve the accurate file name and file type using CordovaFile and CordovaFileTransfer

I have a project where I need to dynamically load files from a website. When you click on a link in the browser, it loads the files with the correct names and extensions. How can I implement this functionality in an Ionic app? I am unsure of how to go ab ...

Guide on incorporating database-sourced audio playback using buttons in PHP and HTML

Building my website with an audio player inside has been a bit challenging. I encountered an issue when trying to combine songs loaded from the database with a play button. My goal is to have the play button change when clicked and load the song from the d ...

Ways to design each element in React

I'm currently working on a React code that involves CSS for Scrolling functionality. When I try to use props.children.map, I encounter an error saying "TypeError: props.children.map is not a function". Since I am in the process of learning React.js, t ...

How to automatically set the radio button as "checked" with Javascript upon loading the page

With the dark mode switch javascript from Bootstrap 5 (https://getbootstrap.com/docs/5.3/customize/color-modes/#javascript), I am attempting to ensure that a radio button is set to "checked" when the page loads, as well as when the color mode is changed. ...

New replacement for routerState.parent feature that has been deprecated in angular2

During my work with Angular 2 rc5, I encountered the following code snippet. this.router.routerState.parent(this.route).params.forEach((params: Params) => { url = params['url']; id = +params['id']; }); I had to resort to th ...

Limiting access to all routes except one

Lately, I've been exploring the combination of ExpressJS + AngularJS and encountered a bit of a tricky situation. My objective is to create a single login page and a dashboard page. By using Passport + MongoDB for user authentication, my plan is to v ...

Encountering an isObject issue while using the @material/core package

When attempting to run the project, I encountered this error in the console: isobject error Upon inspecting the package-lock.json file, I discovered that the isobject dependency was missing in @material-ui/core. Adding it manually resolved the issue. pac ...

Can Sync blocking IO be implemented solely in JavaScript (Node.js) without the use of C code?

Is JavaScript intentionally designed to discourage or disallow synchronous blocking I/O? What is the reason for the absence of a sleep API in JavaScript? Does it relate to the previous point? Can browsers support more than one thread executing JavaScript? ...

Troubleshooting a JavaScript project involving arrays: Let it pour!

I'm a beginner here and currently enrolled in the Khan Academy programming course, focusing on Javascript. I've hit a roadblock with a project called "Make it rain," where the task is to create raindrops falling on a canvas and resetting back at ...

I am looking to have my page refresh just one time

I have created an admin page where I can delete users, but each time I delete a user, the page requires a refresh. I attempted to use header refresh, but this action caused my page to refresh multiple times. Is there a way to ensure that my page only refr ...

Troubleshooting issues with rowspan in a Datatable

I am currently utilizing jQuery DataTables to display my grid data and implementing the rowspan concept with the rowsGroup option. Initially, it works well by spanning some rows and looking visually pleasing, but eventually, it starts failing. Here are so ...

Top method for triggering an action on the client-side during Sign In with the help of Redux, React, and NextAuth

Currently, I am developing a web application that utilizes the Spotify API. My goal is to seamlessly load the user's playlists as soon as they log in using NextAuth. At the moment, there is a button implemented to trigger playlist loading, but it onl ...

Retrieve XML node through AJAX request

I am in need of using AJAX to retrieve values from XML nodes and then utilize those values within an existing JavaScript function. Here's a sample of the XML data: <cars> <car mfgdate="1 Jan 15" name="Ford" id="1"> <engine litre ...

Hiding labels in an HTML document can be achieved by using CSS

Recently, I've been working on a code that relies on a specific Javascript from Dynamic Drive. This particular script is a form dependency manager which functions by showing or hiding elements based on user selections from the forms displayed. Oddly ...

Delaying the activation of the code until the image upload is complete

I'm having trouble synchronizing code to upload an image using a vue composable, wait for the upload to finish, and then store the Firebase storage URL into a database. Despite getting the URL, the success code fires before the upload is complete. My ...

How can communication be established between JavaScript and a .NET app?

I've been developing a help system using HTML, and I want to include clickable links that can trigger commands in a .NET application (such as guiding users through tutorials or workflows). I have explored the TCard() method for HTML help, but it seems ...

Serious issue: a dependency request is an expression (Warning from Angular CLI)

I am currently exploring the dynamic loading of lazy child routes within a lazy routing module. For example: const serverResponse = [ { path: "transaction", children: [ { path: "finance", modulePath: &qu ...

What is the best way to include an icon before each option in a VuetifyJS combobox?

I'm looking to enhance the combobox feature in VuetifyJS by adding an icon before each option in the dropdown menu. Can someone guide me on how to achieve this functionality? You can check out a sample of the combobox on CodePen here: https://codepen. ...

VARIABLE_NAME isn't functioning properly on the window

The code window.VARIABLE_NAME is not functioning properly and is causing the following error. Can you please provide assistance? Uncaught SyntaxError: Unexpected token. This is the code I have written: var window.testing ...