0

我收到上面提到的错误,我相信这是因为控制器没有正确连接到模块,但是我可能是错的。这是已定义的控制器。

(function () {
'use strict';

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

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

我点击网页上的一个按钮,它会点击这个控制器并点击 openModal 函数。Modal 对象是下面定义的服务。

(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);
    }
  }

})();

这是我的服务:

(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
        }
      });
    }})();

这是我的应用程序:

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

1 回答 1

0

当您向其添加 AddDeviceModalCtrl 控制器时,似乎“WS”模块不可用。请注意,在添加任何控制器或服务之前,您必须确保 Angular 模块已准备就绪。

在单个文件中尝试以下代码:

(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
) {...})();
于 2016-06-07T14:16:27.123 回答