AddDeviceModalCtrl is not defined as a function, it is showing as undefined

I am encountering the error mentioned above, I suspect that it is due to the controller not being properly attached to the module. However, I could be mistaken. Below is the definition of the controller.

(function () {
'use strict';

angular
  .module('WS')
  .controller('AddDeviceModalCtrl', AddDeviceModalCtrl);

/* @ngInject */
function AddDeviceModalCtrl(
  $rootScope,
  $scope,
  $stateParams,
  close,
  Auth,
  device,
  DeviceAPI,
  PathfinderAPI,
  helpers,
  GLOBAL_CONST,
  Notification
) {...})();

When I click a button on the webpage, it triggers this controller and executes the openModal function. The Modal object is a service defined as follows.

(function() {
  'use strict';

  angular
    .module('WS.environment')
    .controller('DevicesCtrl', DevicesCtrl);

  /* @ngInject */
  function DevicesCtrl($rootScope, $scope, $state, $stateParams, DeviceAPI, helpers, GLOBAL_CONST, Modal) {
    angular.extend($scope, {
      openModal: openModal,
      editDevice: editDevice
    });

    angular.extend($scope, {
      devices: [],
      errors: []
    });

    $rootScope.$on('deviceAdded', onUpdateDeviceList);

    DeviceAPI
      .getDevices()
      .then(onGetDeviceListSuccess);

    function onGetDeviceListSuccess(devices) {
      $scope.devices = devices;
    }

    $rootScope.$on('updateDevicesEvent', function(event, devices) {
      onGetDeviceListSuccess(devices);
    });

    function openModal($event) {
      Modal.showAddDevice($scope.device);
    }

    function editDevice($event, device) {
      Modal.showEditDevice(device);
    }

    function onUpdateDeviceList($event, device) {
      $scope.devices.push(device.device);
    }
  }

})();

Below is my service definition.

(function() {
  'use strict';

  angular
    .module('WS.service')
    .factory('Modal', Modal);

  /* @ngInject */
  function Modal($rootScope, ModalService) {
    var service = {
      showAddDevice: showAddDevice,
      showEditDevice: showEditDevice,
      showConfirmation: showConfirmation,
      showTimeRange: showTimeRange
    };

    return service;

    function showAddDevice(device) {
      $rootScope.modalHasOpen = true;

      return ModalService.showModal({
        templateUrl: 'modules/modals/device/add/views/device.html',
        controller: 'AddDeviceModalCtrl',
        inputs: {
          device: device
        }
      });
    }})();

Lastly, here is my app configuration.

WS.app = angular
  .module('WS', [
    'interceptors',
    'WS.common',
    'WS.account',
    'WS.layout',
    'WS.dashboard',
    'WS.environment',
    'WS.service',
    'WS.settings'
  ])
  .config(config)
  .run(run);

Answer №1

It appears that the 'WS' module was not accessible when you included the AddDeviceModalCtrl controller. Remember to ensure that the angular module is loaded before adding any controllers or services to it.

Here is an example of how you can organize your code in a single file:

(function () {
'use strict';

WS.app = angular
  .module('WS', [
    'interceptors',
    'WS.common',
    'WS.account',
    'WS.layout',
    'WS.dashboard',
    'WS.environment',
    'WS.service',
    'WS.settings'
  ])
  .config(config)
  .run(run);

angular
  .module('WS')
  .controller('AddDeviceModalCtrl', AddDeviceModalCtrl);

/* @ngInject */
function AddDeviceModalCtrl(
  $rootScope,
  $scope,
  $stateParams,
  close,
  Auth,
  device,
  DeviceAPI,
  PathfinderAPI,
  helpers,
  GLOBAL_CONST,
  Notification
) {...})();

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

Utilize Webpack to integrate redux-form as an external library

I currently have a range of imports in my project, such as: import {Field, reduxForm, FormSection, formValueSelector} from 'redux-form'; My goal is to treat the redux-form imports as an external library so that they do not get included in the b ...

Having trouble getting dayjs to work in the browser with Vue.js?

Trying to display date differences in a human-readable format using the guide found here: I'm attempting to incorporate DayJS as a component in my VueJS application like this: <script src="{{ asset('/vendor/vuejs/vue.js') }}" t ...

What is the purpose of including an es directory in certain npm packages?

Why do developers sometimes have duplicated code in an es folder within libraries? Here are a few examples: https://i.stack.imgur.com/BWF6H.png https://i.stack.imgur.com/3giNC.png ...

What is the best way to free up memory after receiving responseText in a continuous streaming request?

Utilizing xmlHTTPRequest to fetch data from a continuous motion JPEG data stream involves an interesting trick where responseText can populate data even before the request is completed, since it will never actually finish. However, I have encountered some ...

Creating effective puppeteer tests with reasonable expectations

Imagine I have a list of objects and a create button. Typically, the objects are created quickly without any loading indicator. Here is an example of my creation test: const items = await page.$$('.item'); const itemsCount = items.length; await ...

jQuery and HTML: Need help enabling an <input> or <select> element?

Currently, I am using Mozilla Firefox 14.0.1 and Google Chrome 20.0.1132.57 (which I believe is the latest version). The code I am working with looks like this: http://jsfiddle.net/SVtDj/ Here is what I am trying to accomplish: Type something into inpu ...

How to render in Express.js without overwriting HTML elements (such as <p> tags)

I am currently working on a project that resembles a blog and I have a requirement to display text without altering the HTML tags. ./app.js //app.js ... var text = 'Hello <b>World</b>' app.get('/', (req, res)=>{ res ...

Struggling with the task of assigning a glTF item to a separate layer within Three.js

Exploring the use of layers in Three.js. This script includes a sphere, a triangle, and a glTF object (car). I activated a second layer: camera.layers.enable(1); Assigned the sphere, triangle, and glTF object to layer 1: car.layers.set( 1 ); sphere.lay ...

Execute a function using a click event within a statement

Is it possible to trigger a function with parameters based on the result of a statement? For example, can we achieve something like this: (click)="datavalue.elementDataCollection.length > 1 ? AddNewDialog (datavalue,datavalue.COCLabel,mainindex,i) : r ...

Terminate the rethinkdb data stream

Currently delving into the world of RethinkDB and am eager to utilize the changes() method to fetch a changefeed. While I've figured out how to initiate them, the documentation doesn't quite explain how to halt a changefeed. Is it sufficient to ...

Tips for adjusting the maximum height of the column panel within the DataGrid element

I'm trying to adjust the max-height of a column panel that opens when clicking the "Columns" button in the Toolbar component used in the DataGrid. I am working with an older version of @material-ui/data-grid: "^4.0.0-alpha.8". https://i.stack.imgur.c ...

The production build encountered an issue as it was anticipating 3 arguments, however, it only received

import { Pipe, PipeTransform } from '@angular/core'; @Pipe({ name: 'elipsis' }) export class ElipsisPipe implements PipeTransform { transform(text, length, clamp) { text = text || ''; clamp = clamp || '...& ...

Utilize React to generate HTML content and send it as the email body through Node.js

I am currently working on a react application that consists of two main pages - AddStatus and ViewStatus. Both of these are implemented as react components. My current task involves sending out an email daily at a specific time, containing the details dis ...

Is it possible to generate AMP pages using React server-side?

After experimenting with rendering the AMP page by generating HTML on the server using React, I have successfully created a component that fetches data from the API and renders the necessary amp tags. The component is responsible for producing a plain HT ...

Retrieving an Element that Triggered an HTTP GET Request in Node.js with Express

In my Express front-end development project, I have a table with rows containing links that trigger GET requests. These requests are sent to the back-end, which is created using node.js, in order to retrieve files corresponding to each row. All links follo ...

When utilizing the ng-strict-di directive in AngularJS 1.3 with the ngbp framework, the application fails to load properly on the Chrome browser

I am currently developing a web application with AngularJS using the ngbp framework, previously known as ng-boilerplate. The default version of AngularJS in this framework is 1.2, but we are considering switching to 1.3 due to some appealing features it of ...

Unable to attach the script to recently added DOM elements

After spending considerable time working on this, I'm still unable to figure it out. You can find the page I am referring to at: The "show more" button at the bottom triggers additional posts to be displayed on the page using the following script: ...

A step-by-step guide on creating a unique ticket number sequence in PHP

Looking to create a unique ticket number sequence using PHP? Here's the given sequence: 1-W1 (mandatory). 2-Date (yy-dd-mm) format. 3-001-999 (resets daily from 001). Check out this example: e.g. - W120200101001 I've started the code below, b ...

What is the process for modifying the characteristics of an RMWC Component?

How can I dynamically change the icon attribute in my RMWC Button element when an onClick event occurs? <Button outlined icon={<CircularProgress />} onClick={(e)=> { // e.currentTarget.icon = ''; // console.log(e.c ...

Leveraging the power of Ajax in JavaScript

For my assignment, I successfully made two separate paragraphs hide and show using jQuery. Moving forward, the next step involves integrating JavaScript Ajax code to allow the paragraphs to toggle visibility. To achieve this, I created two distinct HTML fi ...