2016-04-08 77 views
-1

無法實例化模塊marbleApp,原因是: 錯誤:[$ injector:nomod]模塊'marbleApp'不可用!您拼錯了模塊名稱或忘記加載模塊名稱。如果註冊模塊確保您指定依賴關係作爲第二個參數。

我已閱讀幾乎每篇文章並通過文檔搜索,但我的應用程序將無法正常工作,因爲我的模塊沒有被加載。任何人都可以找到代碼中的任何錯誤,以防止它正常工作?

的Index.html:

<!DOCTYPE html> 
    <html ng-app="marbleApp"> 
    <head> 
     <title>Marble.com AngularMongo</title> 
     <meta name="viewport" content="width=device-width, initial-scale=1.0"/> 
     <!--Import materialize.css--> 
     <link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> 
     <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.6/css/materialize.min.css" media="screen,projection"/> 
     <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.3/angular.js"></script> 
     <script src="app.js"></script> 

    </head> 

    <body> 

     {{"anot" + "her test"}} 

     <nav style="background-color: #d56324!important"> 
     <div class="nav-wrapper"> 
      <form action="/cosmicblack" method="GET"> 
      <div class="input-field"> 
       <input id="search" type="search" required placeholder="Search"> 
       <label for="search"><i class="material-icons">search</i></label> 
       <i class="material-icons">close</i> 
      </div> 
      </form> 
     </div> 
     </nav> 
     <br> 

     <div> 
    {{"This is " + "a test!"}} 
    {{materials.name}} 
     </div> 
    <!-- <div ng-controller="repeatCtrl">{{materials.name}}</div> --> 



    <div class="container"> 
    <div class="row"> 


     <div class="col m3" ng-controller='repeatCtrl'> 
      <a href="/cosmicblack"><div class="card"> 
      <div class="card-image small"> 
       <img src="http://marble.com/uploads/materials/499/300X300/thumbnail/Cosmic-Black_APeruB9I056YsF3mZ0sT.jpg"> 
       <span class="card-title" ng-bind="materials.name"></span> 
       </div> 
      </div> 
      </a> 
     </div> 


     </div> 
    </div> 







     <!--Import jQuery before materialize.js--> 

     <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.6/js/materialize.min.js"></script> 


    </body> 
    </html> 

app.js:

var app = angular.module('marbleApp', []); 

app.controller('repeatCtrl', function($scope) { 
    $scope.materials = [ 
     {name: 'Cosmic Black'} 
    ];  
}); 

server.js:

console.log('May Node be with you'); 

var express = require('express'); 
var bodyParser = require('body-parser'); 
var app = express(); 
var mongoose = require('mongoose'); 

mongoose.connect('mongodb://localhost/test'); 
var db = mongoose.connection; 

app.use(bodyParser.urlencoded({extended: true})) 

app.get('/', (req, res) => { 
    res.sendFile(__dirname + '/index.html'); 
}); 



app.get('/cosmicblack', (req, res) => { 
    var cursor = db.collection('materials').find(); 
    db.collection('materials').find({"id": "499"}).toArray(function(err, results) { 
     console.log(results); 
    }); 
    db.collection('materialphotos').find({"material_id": "499"}).toArray(function(err, results2) { 
     console.log(results2); 
    }); 
    res.redirect('/'); 
}); 



app.listen(3000,() => { 
    console.log('Running app.js on 3000'); 
}); 
+0

您的代碼正在爲我工​​作。我沒有看到任何問題。 – Danda

回答

0

我已經複製相同的代碼爲你的,它適用於我。看看這個binnomod角度錯誤的常見原因是angular.js或您的應用程序的任何依賴項未正確加載導致您的應用程序模塊無法正確加載

+0

它適用於表達式測試,但是當代碼碰到ng-controller =「repeatCtrl」時,應該從$ scope對象中渲染materials.name,但它不會。它不僅不顯示名稱,而且表達甚至不顯示。 – MattP

+0

你的錯誤是你試圖從'$ scope.materials'數組訪問'.name'。嘗試使用'{{materials [0] .name}}'。我已經更新了相同的垃圾箱 –

+0

當您運行代碼時,您是否簡單地在Chrome中打開它?我認爲我的node.js/express服務器可能存在問題。當我運行我的服務器並轉到本地主機時,代碼不起作用。但是,當我直接在瀏覽器中打開它時,它工作正常。任何想法爲什麼會是這樣? – MattP

相關問題