【问题标题】:Angular script open in browser on port 3000 but it points to port 8383Angular 脚本在浏览器的 3000 端口上打开,但它指向 8383 端口
【发布时间】:2015-03-30 08:26:03
【问题描述】:

过去几周我一直在使用教程在 Angular 中编写脚本。大多数情况下这都能正常工作。

问题是当我运行我的脚本时,浏览器没有指向端口 3000。

以下是 - 来自终端的命令显示我已经启动了服务器并且正在监听端口 3000。 - 显示端口 3000 的代码

我在 Mac 上,从终端导航到项目文件并输入

node server.js 

启动服务器。它返回

listening on port3000

我今天正在学习一个教程,虽然我正在监听端口 3000 并且在我的 server.js 文件中我有代码

app.listen(3000);
console.log('server running on port 3000');

URL 显示端口 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>

有人可以澄清一下我在这里缺少什么。

谢谢。

【问题讨论】:

  • 这似乎与Angular无关,只能通过分享你的Node代码来解决
  • URL 显示端口 8383 是什么意思?网址来自哪里?访问 localhost:3000 会发生什么?
  • 您在问题中提供的大部分代码都是无关紧要的,除了快递代码。您能否尝试更好地解释您看到 8383 的位置?
  • @simonH 我已经添加了浏览器输出的 imgur 中的所有代码和图像。 i.imgur.com/ayEer1I.jpg 谁在降级这篇文章。这是相关的。技术路径有时令人困惑。 - 是的 ?感谢您的帮助
  • @KrisHollenbeck Kris 当我输入 localhost:3000 时,浏览器输出无法获取 /

标签: angularjs node.js port


【解决方案1】:

到目前为止,您发布的代码中没有任何内容可以帮助我们解释端口问题,但是您的图片显示由于未创建模块且未在其背面定义控制器而导致出现角度错误。请参阅此 sn-p 了解所需的格式:

angular.module('myApp', []).
controller('AppCtrl' function ($scope, $http)....

【讨论】:

  • 再次感谢,我能整理出的角码。我有一堆类似的脚本可以工作。我只是对为什么我不从节点端口 3000 启动感到非常困惑。如果您提出一些建议,我将不胜感激。如果你明白我的意思,我需要离开一段时间。
猜你喜欢
  • 1970-01-01
  • 2021-04-30
  • 1970-01-01
  • 2020-11-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多