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

Learning how to implement server side rendering in React JS through tutorials

After diving into the world of React js and mastering the basics, I successfully created web pages using this technology. I also honed my skills with node js and express. However, now I am faced with a new challenge: server side rendering. The tutorials av ...

Implementing multiple filters with jQuery

Make a Selection `<select class="form-control" id="technology"> <option name="sort" value="2g" id="2g"gt;2G</option> <option name="sort" value="3g" id="3g"&g ...

Issues with ng-repeat causing the Angular Editable table to malfunction

<table class="table table-bordered"> <tbody> <tr ng-repeat="playerOrTeam in template.editableTable track by $index"> <td style="text-align: center;" ng-repeat="playerOrTeamCat in playerOrTeam track by $index"> ...

To include a request parameter in every HTTP request made with $http in AngularJS

I am looking to utilize Angular's $http service to communicate with an API. However, I need to find a way to save my authorization token within $http so that it is included in every request, whether it is a post, get, put, or delete request. I have ob ...

Submit simple text via XMLHttpRequest to an Express server

I am currently facing an issue with making a post XMLHttpRequest to my Express server. Despite attempting to send a string, it seems that I am missing something crucial in my implementation. Client: const sendMessage = () => { const message = "This ...

How to access a variable in an Angular Factory's callback function from outside the factory

Here's a look at the structure of My Factory: .factory('MyFactory', function(){ return: { someFunction: functon(firstParam, secondParam, resultObject) { $http.get(url).success(resultObject); } ...

JavaScript substring() function in clone is experiencing an error

I am currently working on a JavaScript function that determines whether a specific substring is present in a larger main string. For instance, if the main string is "111010" and the substring is "011," the expected result should be false since the substr ...

What is the best way to utilize ng-if to conceal a component in AngularJS when a button in a separate component is clicked?

I am facing a challenge with two child components within a parent component. My goal is to hide component1 when a button in component2 is clicked. Below is an illustration of the current code I am handling: Parent Component HTML: <div ng-app='ap ...

Unable to retrieve the value property from document.getElementById as it is null

Can someone help me with reading the input field value in my code? <input type="text" name="acadp_fields[1200]" class="text" placeholder="" value="December 26, 1969"> Here is the code snippet I am us ...

Square-shaped arch chart utilizing Highcharts library

For my project, I have a unique challenge of creating an Arched square chart using High Charts. Despite my efforts, I have not been able to find any suitable platform that demonstrates this specific requirement. The task at hand is outlined as follows – ...

Verify whether the document includes a class that closely matches the provided string using Javascript

I need help identifying elements that include the letters 'ad'. For example: <iframe class="container" /> <!-- Not relevant --> <a class="adp" /> <!-- Relevant --> <a class="adleft" /> ...

What is the process for generating an HTML document from start to finish with the 'html-element' node module?

Here is an example that demonstrates a flawed method: const HTML = require('html-element'); const doc = `<body> </body>`; const page = HTML.document.createElement(doc) page.appendChild('<div>1</div>') page.append ...

Ways to deactivate just the Clicked button in a mapped over component

Utilizing the request variable, I am displaying an array of objects on the page. Each object in the array contains properties such as question, correct_answer, and incorrect_answer. Moreover, I have implemented a state called disable which toggles between ...

Performing a count query with MongoDB Mongoose by grouping data based on multiple fields

I've developed an analytics API using MongoDB. Here is the model for my sessions: const sessionSchema = new Schema( { user: { id: Number, name: String, email: String }, }, { timestamps: true }, ); My goal is to calculate the number of uni ...

Replicate the preceding input data by simply clicking a button

Here is some HTML and jQuery code that I am working with: $(".btn-copy").click(function() { var previousContent = $(this).prev()[0]; previousContent.select(); document.execCommand('copy'); }); <script src="https://cdnjs.cloudflare.com ...

Error encountered: Unable to call JavaScript across processes during the click command in Selenium IDE

My current setup involves using an SPA built on AngularJS 1 and Selenium IDE 2.9.1 for functional testing. One of the challenges I am facing is with a button that has an onclick handler on a form. Whenever I try to click this button during a test scenario ...

Errors are encountered when attempting to use `usePathname()` and `useRouter()` functions. `usePathname()` returns null while `useRouter()` causes errors stating "NextRouter not mounted" and "invariant

I'm encountering an issue with implementing active navlinks in NextJS version 13.4.4. I need to access the current URL for this solution, but every attempt ends up failing. My folder structure is organized as follows: .next components Header header ...

Unlock real-time alerts with the power of JavaScript and PHP!

I am currently working on enhancing my skills in javascript. I have a basic idea of what I want to achieve. My goal is to create an automated javascript function that accesses a php page. This php page will create an array of new notifications for the ja ...

Utilizing ng-model on a pair of inputs to achieve synchronized values

Is it possible to use ng-model on an input field that receives a value from another input field? I'm having issues with my code and I can't figure out why. Can ng-model be set to an input field using Angular values? Here's my code: ...

5 steps to create a versatile function for activating attributes based on their values

Hey everyone! I was working on creating this calculator and I had different options to implement it, but I wanted to do it in a specific way. <form action=""> <label for="num1">Number A</label><br> <input type="number" na ...