2015-11-15 2 views
0

«[инжектор: modulerr] Не удалось создать экземпляр модуля из-за: [$ injector: nomod] Модуль «стартер» недоступен! Вы либо ошибочно написали имя модуля, либо забыли его загрузить. Если регистрация модуля гарантирует, что вы определяете зависимости как второй аргумент ».

Я начал получать эту неприятную ошибку на моей консоли, пока я работал над новой функцией для своего приложения для ионических приложений. Я перешел через свои модули, переместил несколько тегов скриптов, и я все еще не могу понять это. Я видел, как другие люди с этой ошибкой помещают ng-app в голову, что я и сделал, и это не сработало. Я не касался ng-app или angular.module в верхней части app.js, когда я начал получать эту ошибку. Может ли кто-нибудь помочь указать мне в правильном направлении?

index.html

<!DOCTYPE html> 
<html> 
    <head> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width"> 
    <title></title> 

    <link href="css/ionic.css" rel="stylesheet"> 
    <link href="css/style.css" rel="stylesheet"> 
    <meta http-equiv="Content-Security-Policy" content="script-src 'self' https://maps.googleapis.com/ https://maps.gstatic.com/ https://mts0.googleapis.com/ 'unsafe-inline' 'unsafe-eval'"></meta> 

    <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above 
    <link href="css/ionic.app.css" rel="stylesheet"> 
    --> 
<script src="https://maps.googleapis.com/maps/api/js"></script> 
    <!-- ionic/angularjs js --> 
    <script src="js/ionic.bundle.js"></script> 

    <!-- cordova script (this will be a 404 during development) --> 
    <script src="js/ng-cordova.min.js"></script> 
     <script src="js/cordova.js"></script> 


    <!-- your app's js --> 
    <script src="js/app.js"></script> 
    <script src="js/controllers.js"></script> 
    <script src="css/style.css"></script> 
     <script src="scss/ionic.app.scss"></script> 
    </head> 
    <body ng-app="starter"> 
    <!-- 
     The nav bar that will be updated as we navigate between views. 
    --> 
    <ion-nav-bar class="bar-stable"> 
     <ion-nav-back-button> 
     </ion-nav-back-button> 
    </ion-nav-bar> 

    <ion-nav-view></ion-nav-view> 

    </body> 
</html> 

app.js

angular.module('starter', ['ionic', 'starter.controllers', 'ngCordova']) 

.run(function($ionicPlatform, GoogleMaps) { 
    $ionicPlatform.ready(function() { 
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard 
    // for form inputs) 
    if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) { 
     cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); 
     cordova.plugins.Keyboard.disableScroll(true); 

    } 
    if (window.StatusBar) { 
     // org.apache.cordova.statusbar required 
     StatusBar.styleDefault(); 
    } 
    GoogleMaps.init(); 
    }); 
}) 

$http.get('http://example.com').then(function(response){ 
    //the response from the server is now contained in 'response' 
}, function(error){ 
    //there was an error fetching from the server 
}); 

.config(function($stateProvider, $urlRouterProvider) { 

    // Ionic uses AngularUI Router which uses the concept of states 
    // Learn more here: https://github.com/angular-ui/ui-router 
    // Set up the various states which the app can be in. 
    // Each state's controller can be found in controllers.js 
    $stateProvider 

    // setup an abstract state for the tabs directive 

     .state('tab', { 
    url: '/tab', 
    abstract: true, 
    templateUrl: 'templates/tabs.html' 
    }) 

    // Each tab has its own nav history stack: 



    .state('tab.home', { 
    url: '/home', 
    views: { 
     'tab-home': { 
     templateUrl: 'templates/tab-home.html', 
     controller: 'DashCtrl' 
     } 
    } 
    }) 

    .state('tab.exteriorpainting', { 
     url: "/exteriorpainting", 
     views: { 
     'tab-home': { 
      templateUrl: "services/exteriorPainting.html" 
     } 
     } 
    }) 

    .state('tab.map', { 
     url: "/map", 
     views: { 
     'tab-home': { 
      controller: 'MapCtrl', 
      templateUrl: 'templates/map.html' 
     } 
     } 
    }) 

.state('tab.login', { 
     url: '/login', 
     views: { 
     'tab-login': { 
      templateUrl: 'templates/tab-login.html', 
      controller: 'DashCtrl' 
     } 
     } 
    }) 

    .state('tab.signup', { 
    url: '/signup', 
    views: { 
     'tab-signup': { 
     templateUrl: 'templates/tab-signup.html', 
     controller: 'AccountCtrl' 
     } 
    } 
    }); 

    // if none of the above states are matched, use this as the fallback 
    $urlRouterProvider.otherwise('tab/home'); 

}); 

.factory('Markers', function($http) { 

    var markers = []; 

    return { 
    getMarkers: function(){ 
    return $http.get("http://example.com/markers.php").then(function(response){ 
      markers = response; 
      return markers; 
    }, 
    getMarker: function(id){ 

    } 
    } 
}} 

.factory('GoogleMaps', function($cordovaGeolocation, Markers){ 

    var apiKey = false; 
    var map = null; 

    function initMap(){ 

    var options = {timeout: 10000, enableHighAccuracy: true}; 

    $cordovaGeolocation.getCurrentPosition(options).then(function(position){ 

     var latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); 

     var mapOptions = { 
     center: latLng, 
     zoom: 15, 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
     }; 

     map = new google.maps.Map(document.getElementById("map"), mapOptions); 

     //Wait until the map is loaded 
     google.maps.event.addListenerOnce(map, 'idle', function(){ 

     //Load the markers 
     loadMarkers(); 

     }); 

    }, function(error){ 
     console.log("Could not get location"); 

     //Load the markers 
     loadMarkers(); 
    }); 

    } 

    function loadMarkers(){ 

     //Get all of the markers from our Markers factory 
     Markers.getMarkers().then(function(markers){ 

     console.log("Markers: ", markers); 

     var records = markers.data.result; 

     for (var i = 0; i < records.length; i++) { 

      var record = records[i]; 
      var markerPos = new google.maps.LatLng(record.lat, record.lng); 

      // Add the markerto the map 
      var marker = new google.maps.Marker({ 
       map: map, 
       animation: google.maps.Animation.DROP, 
       position: markerPos 
      }); 

      var infoWindowContent = "<h4>" + record.name + "</h4>";   

      addInfoWindow(marker, infoWindowContent, record); 

     } 

     }); 

    } 

    function addInfoWindow(marker, message, record) { 

     var infoWindow = new google.maps.InfoWindow({ 
      content: message 
     }); 

     google.maps.event.addListener(marker, 'click', function() { 
      infoWindow.open(map, marker); 
     }); 

    } 

    return { 
    init: function(){ 
     initMap(); 
    } 
    } 

}) 

controllers.js

angular.module('starter.controllers', ['ionic', 'ngCordova']) 

.controller('DashCtrl', function($scope) {}) 

.controller('MapCtrl', function($scope, $state, $cordovaGeolocation) { 

}); 
+0

Я удалил завод в app.js, и мое приложение, похоже, работает нормально. Что это такое о фабрике, которая давала мне эту ошибку, потому что мне все еще нужно ее для моего приложения? – fergy

+0

Вы можете создать jsFiddle? – Aqdas

ответ

0

Я уверен, что вы, вероятно, уже понял, это один из. Но просто сообщение в случае помогает кому-то другому. У меня был этот точный вопрос, когда я начал использовать ион. Ключом было снятие фабрики. Вы прекратили свой «конфиг» с помощью двоеточия, но затем приковали завод сразу после него. У вас также есть точка с запятой после .run, поэтому вы должны удалить это. Кроме того, каждая фабрика должна заканчиваться символом «)», если вы связываете их так же, как и вы. Поэтому я просто удалил полуточку и добавил «)», и он отлично работает. Вам не нужно иметь $ http.get к example.com, который у вас есть после .run. Вы уже были так близки, как я. Я разместил код с кодом ниже

angular.module('starter', ['ionic', 'starter.controllers', 'ngCordova']) 
.run(function($ionicPlatform, GoogleMaps) { 
    $ionicPlatform.ready(function() { 
     // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard 
     // for form inputs) 
     if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) { 
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); 
      cordova.plugins.Keyboard.disableScroll(true); 

     } 
     if (window.StatusBar) { 
      // org.apache.cordova.statusbar required 
      StatusBar.styleDefault(); 
     } 
     GoogleMaps.init(); 
    }); 
}).config(function($stateProvider, $urlRouterProvider) { 

// Ionic uses AngularUI Router which uses the concept of states 
// Learn more here: https://github.com/angular-ui/ui-router 
// Set up the various states which the app can be in. 
// Each state's controller can be found in controllers.js 
$stateProvider 

    // setup an abstract state for the tabs directive 

    .state('tab', { 
     url: '/tab', 
     abstract: true, 
     templateUrl: 'templates/tabs.html' 
    }) 
    .state('tab.home', { 
     url: '/home', 
     views: { 
      'tab-home': { 
       templateUrl: 'templates/tab-home.html', 
       controller: 'DashCtrl' 
      } 
     } 
    }) 

    .state('tab.exteriorpainting', { 
     url: "/exteriorpainting", 
     views: { 
      'tab-home': { 
       templateUrl: "services/exteriorPainting.html" 
      } 
     } 
    }) 

    .state('tab.map', { 
     url: "/map", 
     views: { 
      'tab-home': { 
       controller: 'MapCtrl', 
       templateUrl: 'templates/map.html' 
      } 
     } 
    }) 

    .state('tab.login', { 
     url: '/login', 
     views: { 
      'tab-login': { 
       templateUrl: 'templates/tab-login.html', 
       controller: 'DashCtrl' 
      } 
     } 
    }) 

    .state('tab.signup', { 
     url: '/signup', 
     views: { 
      'tab-signup': { 
       templateUrl: 'templates/tab-signup.html', 
       controller: 'AccountCtrl' 
      } 
     } 
    }); 
$urlRouterProvider.otherwise('tab/home');}).factory('Markers', function($http) { 

var markers = []; 

return { 
    getMarkers: function(){ 
     return $http.get("http://example.com/markers.php").then(function(response){ 
       markers = response; 
       return markers; 
      }, 
      getMarker: function(id){ 

     } 
    } 
}}).factory('GoogleMaps', function($cordovaGeolocation, Markers){ 

    var apiKey = false; 
    var map = null; 

    function initMap(){ 

     var options = {timeout: 10000, enableHighAccuracy: true}; 

     $cordovaGeolocation.getCurrentPosition(options).then(function(position){ 

      var latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); 

      var mapOptions = { 
       center: latLng, 
       zoom: 15, 
       mapTypeId: google.maps.MapTypeId.ROADMAP 
      }; 

      map = new google.maps.Map(document.getElementById("map"), mapOptions); 

      //Wait until the map is loaded 
      google.maps.event.addListenerOnce(map, 'idle', function(){ 

       //Load the markers 
       loadMarkers(); 

      }); 

     }, function(error){ 
      console.log("Could not get location"); 

      //Load the markers 
      loadMarkers(); 
     }); 

    } 

    function loadMarkers(){ 

     //Get all of the markers from our Markers factory 
     Markers.getMarkers().then(function(markers){ 

      console.log("Markers: ", markers); 

      var records = markers.data.result; 

      for (var i = 0; i < records.length; i++) { 

       var record = records[i]; 
       var markerPos = new google.maps.LatLng(record.lat, record.lng); 

       // Add the markerto the map 
       var marker = new google.maps.Marker({ 
        map: map, 
        animation: google.maps.Animation.DROP, 
        position: markerPos 
       }); 

       var infoWindowContent = "<h4>" + record.name + "</h4>"; 

       addInfoWindow(marker, infoWindowContent, record); 

      } 

     }); 

    } 

    function addInfoWindow(marker, message, record) { 

     var infoWindow = new google.maps.InfoWindow({ 
      content: message 
     }); 

     google.maps.event.addListener(marker, 'click', function() { 
      infoWindow.open(map, marker); 
     }); 

    } 

    return { 
     init: function(){ 
      initMap(); 
     } 
    } 

}) 
Смежные вопросы