Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 角度UI布线未将“我的部分”加载到视口中_Angularjs_Node.js_Routing - Fatal编程技术网

Angularjs 角度UI布线未将“我的部分”加载到视口中

Angularjs 角度UI布线未将“我的部分”加载到视口中,angularjs,node.js,routing,Angularjs,Node.js,Routing,我有一个Node.JS+Express后端,正在尝试设置一个有角度的前端 我有一个名为common.HTML的基本HTML模板: <!DOCTYPE HTML> <html> <head> <title>Watson-Amadeus</title> <link rel = "stylesheet" href = "css/index.css" />

我有一个Node.JS+Express后端,正在尝试设置一个有角度的前端

我有一个名为
common.HTML
的基本HTML模板:

<!DOCTYPE HTML>
    <html>
        <head>
            <title>Watson-Amadeus</title>
            <link rel = "stylesheet" href = "css/index.css" />
            <link rel = "stylesheet" href = "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
            <link rel = "script" href = "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"  />
            <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
            <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/1.0.3/angular-ui-router.min.js"></script>
            <script src="js/amadeus.js"></script>
        </head>
        <body ng-app = "watson_amadeus">
            <div ui-view>
            </div>
        </body>
    </html>
intro.html
watson amadeus.html
则只是其中包含一些html的片段。我的节点服务器代码如下所示:

var express = require('express'),
amadeus = require('./rest/amadeus.js'),
body_parser = require('body-parser');

var app = express();

app.use(body_parser.json());
app.use(body_parser.urlencoded({extended: false}));
app.use(express.static("public"));  // Use static pages from the public directory

app.post("/api/amadeus/", amadeus.send_message);
app.get("*", (req, res) => {
  res.sendFile(__dirname + "/public/common.html");
});

app.listen(8080);  // Set the server to listen on port 8080
最后,我的目录结构相当简单:

project_dir

  public

    js

      amadeus.js

    common.html
    index.html
    watson-amadeus.html

  node_server.js
  package.json
当我启动web服务器并尝试
http://localhost:8080/intro
,我看到的只是一个空白屏幕,查看页面源代码显示它只是加载
common.html
,而没有将
index.html
内容按应有的方式放入视口。何况,;当我做
http://localhost:8080/
,我得到index.html的内容,但没有common.html的部分

我是个新手,所以这可能是一些基本的东西,但我不知道我把事情搞砸了

  • 一旦定义了
    app.use(express.static('public')),express server将自动加载index.html,因此
    app.get(“*”,(req,res)=>{res.sendFile(uu dirname+“/public/common.html”);}根本不会运行
  • 我建议将
    common.html
    重命名为
    index.html
    ,因为它是您的主要html

  • 默认情况下,
    ui路由
    将添加
    #
    到url,请尝试
    http://10.8.8.8:8080/
    ,成功加载
    index.html
    后,url实际更改为
    http://10.8.8.8:8080/#!/。
    因此,您可以通过
    http://10.8.8.8:8080/#!/简介

  • 如果您想删除
    #,需要付出很多努力,您可以研究下一步。祝你好运

    amadeusState正在使用template而不是templateUrl,就像在索引中一样。请尝试更改它。谢谢,但不幸的是,这不起作用。啊,我不知道#!事情,谢谢你的建议和更名!我会试试的。是的,把#弹出来!在url中工作!现在我得想办法摆脱它。但至少我知道问题是什么。非常感谢!
    project_dir
    
      public
    
        js
    
          amadeus.js
    
        common.html
        index.html
        watson-amadeus.html
    
      node_server.js
      package.json