0

Ich bekomme den oben genannten Fehler, ich glaube, das ist, weil der Controller nicht ordnungsgemäß an das Modul angeschlossen ist, aber ich könnte falsch liegen. Hier ist der Controller, der definiert wurde.AddDevicemodalCtrl ist keine Funktion, wurde undefiniert

Ich klicke auf eine Schaltfläche auf der Webseite und es trifft diesen Controller und trifft die openModal-Funktion. Das Modal-Objekt ist ein Dienst, der unten definiert ist.

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

})(); 

hier ist mein Service:

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

und dies ist meine App:

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

Antwort

0

Es scheint, dass 'WS' Modul nicht verfügbar war, wenn Sie AddDeviceModalCtrl Controller hinzugefügt. Beachten Sie, dass Sie sicherstellen müssen, dass das Winkelmodul bereit ist, bevor Sie einen Controller oder einen Service hinzufügen.

den Code unten in einer einzigen Datei Versuche:

(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 
) {...})(); 
+0

so soll ich platzieren, die Initialisierung des Reglers unter der Definition des App-Modul – DorkMonstuh

+0

Ja, es ist richtig! –

+0

Sunset, ich benutze Schluck als meine Aufgabe runner und verketten alle Dateien, ich kann sehen, WS-Modul an der Spitze der Datei und alle meine anderen Controller an der Unterseite dies scheint nicht das Problem zu sein – DorkMonstuh