Ionic1错误:[$ injector:modulerr]由于以下原因无法实例化模块启动器:[$ injector:modulerr]

时间:2017-09-19 22:57:19

标签: html angularjs ionic-framework

  

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

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

Error: [$injector:modulerr] Failed to instantiate module starter due to:
[$injector:modulerr] Failed to instantiate module starter.services due to:
[$injector:nomod] Module 'starter.services' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
http://errors.angularjs.org/1.5.3/$injector/nomod?p0=starter.services
minErr/<@http://localhost:8100/lib/ionic/js/ionic.bundle.js:13443:12
module/<@http://localhost:8100/lib/ionic/js/ionic.bundle.js:15409:17
ensure@http://localhost:8100/lib/ionic/js/ionic.bundle.js:15333:38
module@http://localhost:8100/lib/ionic/js/ionic.bundle.js:15407:14
loadModules/<@http://localhost:8100/lib/ionic/js/ionic.bundle.js:17899:22
forEach@http://localhost:8100/lib/ionic/js/ionic.bundle.js:13696:11
loadModules@http://localhost:8100/lib/ionic/js/ionic.bundle.js:17883:5
loadModules/<@http://localhost:8100/lib/ionic/js/ionic.bundle.js:17900:40
forEach@http

app.js

// Ionic Starter App
// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'

angular.module('starter', ['ionic', 'starter.services'])

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

      // Don't remove this line unless you know what you are doing. It stops the viewport
      // from snapping when text inputs are focused. Ionic handles this internally for
      // a much nicer keyboard experience.
      cordova.plugins.Keyboard.disableScroll(true);
    }
    if(window.StatusBar) {
      StatusBar.styleDefault();
    }
  });
})

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

  .state('app', {
    url: '/app',
    templateUrl: "templates/menu.html",
    controller: 'AppCtrl',
    abstract: true
  })

  .state('app.home', {
    url: '/home',
    views: {
      'menuContent': {
        templateUrl: 'templates/home.html',
        controller: 'HomeCtrl'
      }
    }
  });

  $urlRouterProvider.otherwise('/app/home');
})

.controller('AppCtrl', function($scope, WC){

    var Woocommerce = WC.WC();
    Woocommerce.get('products/categories', function(err, data, res){
      console.log(res);
    })
})

.controller('AppCtrl', function(){

})

.controller('HomeCtrl', function(){

})

services.js

angular.module('starter.services',[])
.service('WC', function(){
    return {
        WC: function(){
            var Woocommerce = new WoocommerceAPI({
                url: 'http://samarth.cloudapp.net',
                consumerKey: 'ck_98def17ffa4f32048cb5906d1de4fb35a2cc646a',
                consumerSecret: 'cs_858089ad34205ced8dd85f91e28ad88677c85644',
        wpAPI: true, //or false if you want to use the legacy API v3
        version: 'wc/v2' //or wc/v1
            })
            return Woocommerce;
        }
}});

的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 rel="manifest" href="manifest.json">

    <!-- un-comment this code to enable service worker
    <script>
      if ('serviceWorker' in navigator) {
        navigator.serviceWorker.register('service-worker.js')
          .then(() => console.log('service worker installed'))
          .catch(err => console.log('Error', err));
      }
    </script>-->

    <link href="lib/ionic/css/ionic.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">

    <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
    <link href="css/ionic.app.css" rel="stylesheet">
    -->

    <!-- ionic/angularjs js -->
    <script src="lib/ionic/js/ionic.bundle.js"></script>

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

    <!-- your app's js -->
    <script src="js/app.js"></script>
  </head>
  <body ng-app="starter">
  <ion-nav-view></ion-nav-view>
  </body>
</html>

menu.html

<ion-side-menus>
    <ion-side-menu-content>
        <ion-nav-bar class = "bar-stable">
            <ion-nav-back-button> </ion-nav-back-button>

            <ion-nav-buttons side = "left">
                <button class = "button button-icon button-clear ion-navicon" menu-toggle = "left"> 
                </button>
            </ion-nav-buttons>

            <ion-nav-buttons side = "right">
                <button class = "button button-icon button-clear ion-android-cart">
                    <span class = "badge badge-assertive"> 2 </span>
                </button>

            </ion-nav-buttons>

        </ion-nav-bar>
        <ion-nav-view name = "menuContent"> </ion-nav-view>
    </ion-side-menu-content>

    <ion-side-menu>
        <ion-list>
            <ion-item> Login </ion-item>
            <ion-item> Home </ion-item>
            <ion-item> Browse </ion-item>
            <ion-item class = "item-divider">Categories</ion-item>

        </ion-list>
    </ion-side-menu>
</ion-side-menus>

1 个答案:

答案 0 :(得分:1)

我想您忘了在index.html中添加services.js文件,可以在app.html之后的index.html中添加以下行。

`<!-- your app's js -->
<script src="js/app.js"></script>
<script src="js/services.js"></script>`