我對AngularJS頗爲陌生,並且使用$ http嘗試了一段新代碼。我已經安裝了nodeJS並使用npm安裝了express。當我在節點上運行server.js - node server.js
時,我收到了郵件的收聽。但是當我嘗試在瀏覽器中加載index.html時,我收到一條錯誤消息,說它無法獲取文件。index.html即使在節點服務器運行成功時也不會加載
我的代碼: server.js
var express = require('express'), app = express();
//
//app.configure(function(){
// app.use(express.static(__dirname,'/'));
//});
app.listen(8080, 'localhost');
app.get('/customers/:id', function(req,res){
var customerid = parseInt(req.params.id);
var data = {};
for(var i=0, len = customers.length;i<len;i++){
if(customers[i].id === customerid) {
data = customers[i];
break;
}
}
res.json(data);
});
app.get('/customers', function(req, res){
res.json(customers);
});
console.log('Express listening on port 8080');
var customers = [
{
id:1,
joined: '2012-09-12',
name: 'John',
city:'Chandler',
orderTotal: 22.8699,
orders: [
{
id: 1,
product:'shoes',
total: 9.9956
},
{
id:2,
product: 't-shirts',
total: 12.8743
}
]
},
{
id:2,
joined: '2010-12-02',
name: 'Tina',
city:'New York City',
orderTotal: 10.345,
orders: [
{
id:1,
product: 'shoes',
total: 10.345
}
]
},
{
id:3,
joined: '2013-10-25',
name:'Dave',
city:'Seattle',
orderTotal: 15.534,
orders: [
{
id:1,
product: 'shoes',
total: 8.453
},
{
id:2,
product: 'shorts',
total: 7.081
}
]
},
{
id:4,
joined: '1998-01-15',
name:'Zed',
city:'Las Vegas',
orderTotal: 20.9305,
orders:[
{
id:1,
product: 'shirts',
total: 10.9484
},
{
id:2,
product: 't-shirts',
total: 9.9821
}
]
}
];
的index.html
<!doctype html>
<html ng-app="myApp">
<head>
<title>Routing Demo</title>
<link type="text/css" href="css/styles.css" rel='stylesheet'/>
</head>
<body>
<div ng-view></div>
<script type="text/javascript" src='scripts/angular.js'></script>
<script src="scripts/angular-route.js"></script>
<script type="text/javascript" src='app/app.js'></script>
<script type="text/javascript" src='app/services/customersService.js'></script>
<script type="text/javascript" src='app/controllers/customerCtrl.js'></script>
<script type="text/javascript" src='app/controllers/ordersCtrl.js'></script>
<script type="text/javascript" src='app/services/values.js'></script>
</body>
</html>
請指導我在哪裏,我錯了。我對此很陌生,所以請幫助。
那麼你的項目的目錄結構看起來像解決朝核問題? –