簡體   English   中英

噴油器錯誤在angular.js中找不到模塊?

[英]Injector error no module found in angular.js?

嗨,我已經面對這個問題很長時間了。 我可以在這個地方找到它,這是由於html頁面中的ng-app 但是我在js中有適當的food模塊。 造成此錯誤的原因是什么? 任何想法? 我的密碼

INDEX.HTML

<!DOCTYPE html>
<html ng-app="food">
  <head>
    <title>Scratchpad</title>

    <!-- Viewport mobile tag for sensible mobile support -->
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">


    <!--
        Stylesheets and Preprocessors
        ==============================

        You can always bring in CSS files manually with `<link>` tags, or asynchronously
        using a solution like AMD (RequireJS).  Or, if you like, you can take advantage
        of Sails' conventional asset pipeline (boilerplate Gruntfile).

        By default, stylesheets from your `assets/styles` folder are included
        here automatically (between STYLES and STYLES END). Both CSS (.css) and LESS (.less)
        are supported. In production, your styles will be minified and concatenated into
        a single file.

        To customize any part of the built-in behavior, just edit `tasks/pipeline.js`.
        For example, here are a few things you could do:

            + Change the order of your CSS files
            + Import stylesheets from other directories
            + Use a different or additional preprocessor, like SASS, SCSS or Stylus
    -->
    <!--Twitter Bootstrap-->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
    <!--STYLES-->
    <link rel="stylesheet" href="/styles/importer.css">
    <!--STYLES END-->
  </head>

    <body>
      <nav class = "navbar navbar-default" role = "navigation">
        <div class = "container-fluid">
          <div class = "navbar-header">
            <a class = "navbar-brand" ui-sref = "scratchpad">FoodForShare</a>
          </div>
        </div>

      </nav>


      <p>SAMPLE PAGE</p>

      <div class = "container">
        <div ui-view></div>
      </div>



    <!--

      Client-side Javascript
      ========================

      You can always bring in JS files manually with `script` tags, or asynchronously
      on the client using a solution like AMD (RequireJS).  Or, if you like, you can
      take advantage of Sails' conventional asset pipeline (boilerplate Gruntfile).

      By default, files in your `assets/js` folder are included here
      automatically (between SCRIPTS and SCRIPTS END).  Both JavaScript (.js) and
      CoffeeScript (.coffee) are supported. In production, your scripts will be minified
      and concatenated into a single file.

      To customize any part of the built-in behavior, just edit `tasks/pipeline.js`.
      For example, here are a few things you could do:

          + Change the order of your scripts
          + Import scripts from other directories
          + Use a different preprocessor, like TypeScript

    -->


    <script src="/js/dependencies/sails.io.js"></script>
    <script src="/js/bower_components/angular/angular.min.js"></script>
    <script src="/js/bower_components/angular-route/angular-route.min.js"></script>
    <script src="/js/bower_components/jquery/dist/jquery.min.js"></script>
    <script src="/js/bower_components/bootstrap/dist/js/bootstrap.js"></script>
    <script src="/js/main.js"></script>
    <script src="/js/routes.js"></script>
    <script src="/js/service/crud.js"></script>

  </body>
</html>

MAIN.JS

/**
* Defines module-scratchpadModule for the application
*@dependencies: ui-router , Angular - resource
*@states: 2 Parent states and 1 Child state
*@Controllers: Controllers for listing, viewing and adding a scratch
*@Factory Service: Notes for the angular resource
*
*
*
*
*/
var foodshareModule= angular.module('food',['ngRoute','ngResource']);

console.log("Main file getting included");


foodshareModule.controller("personController", function($scope) {
    console.log($scope);
    $scope.firstName = "John";
    $scope.lastName = "Doe";
    console.log($scope.firstName);
    console.log($scope.lastName);
});

foodshareModule.controller('scratchListController', function($scope,$state,Notes){

   console.log("working");

  $scope.scratchpad =Food.query();

  $scope.deleteScratch = function (scratch,flag) {
    if(flag === 0) {                                            //Checks if Bulk delete or single delete
      if(confirm("You Clicked DELETE !! Are you sure ?")) {
      scratch.$delete(function() {                          //Single delete
        window.location.href = 'http://localhost:1337';
      });
      }
    }
    else {                                                      //Bulk delete
      scratch.$delete(function() {
        window.location.href = 'http://localhost:1337';
      });
    }

  }

  $scope.emptyScratchpad = function () {
    var ask = false;
    if (confirm ("You are about Empty Scratchpad. Sure ????")) {
      ask = true;
    }
    if(ask === true) {
      for (var i = 0; i < $scope.scratchpad.length; i++) {
        $scope.deleteScratch($scope.scratchpad[i],1);
      }
    }

  }
})



foodshareModule.factory('Food', function($resource) {
  return $resource('http://localhost:1337/Food:id', { id: '@_id' }, {
    update: {
      method: 'PUT'
    }
  });
});

錯誤:

Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.3.15/$injector/modulerr?p0=food&p1=TypeError%…calhost%3A1337%2Fjs%2Fbower_components%2Fangular%2Fangular.min.js%3A17%3A1)

您尚未包含ngResource腳本文件。 ngResource沒有預先與angular.js捆綁在一起

<script src="path-to-js/angular-resource.min.js"></script>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM