过去几周我一直在使用教程编写Angular脚本。大多数情况下这一切都很好
问题在于,当我运行脚本时,浏览器未指向端口3000。
以下是 来自终端的命令显示我已经启动了服务器而我正在侦听端口3000。 - 显示端口3000的代码
我在Mac上,从终端,我导航到项目文件并输入
node server.js
启动服务器。它返回
listening on port3000
我今天正在关注一个教程,虽然我正在侦听端口3000并且在我的server.js文件中我有代码
app.listen(3000);
console.log('server running on port 3000');
网址显示端口8383
节点代码:
终端。
macbookpro:projectNodeMichael shane$ cd public_html/
macbookpro:public_html shane$ ls
angular.js index.html public
controllers node_modules server.js
macbookpro:public_html shane$ node server.js
server running on port 3000
server.js
var express = require('express');
var app = express();
//app.get('/', function (req,res){
// res.send('hi from server.js');
//});
// set up html template using an express command
// static is html css and javascript files
// static means tell the server to the static files because they do not change
// dirname is the location
app.use(express.static(__dirname + "/public"));
app.get('/contactList',function(req,res) {
console.log('I received a get request')
});
app.listen(3000);
console.log('server running on port 3000');
controller.js
// connect our controller.js file with our index.html file
// test it is working properly
function AppCtrl($scope, $http) {
console.log("hello world from controller")
$http.get('/contactList')
person1 = {
name: "tim",
email: "tim@email.com",
number: '222 222-2222'
};
person2 = {
name: "jim",
email: "jim@email.com",
number: '333 222-2222'
};
var contactList =[person1, person2, person3];
($scope.contactList) = contactList;
}
的index.html
的index.html
<div class ="container" ng-controller = "AppCtrl">
<h1>Contact List App</h1>
<table class="table">
<thead>
<tr>
<th> name</th>
<th> email</th>
<th> number</th>
</tr>
</thead>
<tbody>
<tr ng-repeat = contact in contactList>
<td>{{contact.name}}</td>
<td>{{contact.email}}</td>
<td>{{contact.number}}</td>
</tr>
</tbody>
</table></div>
<script src ="angular.js"></script>
<script src="controllers/controller.js"></script>
有人可以澄清我在这里缺少的东西。
感谢。
答案 0 :(得分:0)
到目前为止,您发布的代码中没有任何内容可以帮助我们解释端口问题,但是您的图片显示由于没有创建模块而没有在后面定义控制器而导致角度错误。请参阅此代码段以了解所需的格式:
angular.module('myApp', []).
controller('AppCtrl' function ($scope, $http)....