我的控制台出错 - [$ injector:modulerr]由于以下原因无法实例化模块启动器:[$ injector:nomod]模块'starter'不可用

时间:2015-11-15 00:36:49

标签: javascript angularjs ionic-framework

“[$ injector:modulerr]由于以下原因导致无法实例化模块启动器: [$ injector:nomod]模块'starter'不可用!您要么错误拼写了模块名称,要么忘记加载它。如果注册模块,请确保将依赖项指定为第二个参数。“

当我为Ionic应用程序开发新功能时,我开始在控制台中收到这个令人讨厌的错误。我已经浏览了我的模块,移动了一些脚本标签,我仍然无法解决这个问题。我已经看到其他人有这个错误把ng-app放在头部,我做了,但它没有用。当我开始收到此错误时,我没有触及app.js顶部的ng-app或angular.module。有人可以帮助我指出正确的方向吗?

的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) {

});

1 个答案:

答案 0 :(得分:0)

我相信你可能已经想出了这个。但只是张贴以防万一其他人。当我开始离子时,我遇到了这个问题。你搬掉工厂是关键。你终止了你的&#34; config&#34;用分号,然后在它之后把工厂链接起来。在.run之后你也有分号,所以你应该删除它。此外,每个工厂必须以&#34;)&#34;如果你像你一样链接他们。所以我刚刚删除了分号并添加了&#34;)&#34;它工作正常。您不需要在.run之后拥有$ http.get到example.com。你已经和我一样亲密了。我发布了下面的重做代码

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

})