Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/80.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
Html 具有角度单击值的NodeJS路由重定向页面_Html_Angularjs_Node.js - Fatal编程技术网

Html 具有角度单击值的NodeJS路由重定向页面

Html 具有角度单击值的NodeJS路由重定向页面,html,angularjs,node.js,Html,Angularjs,Node.js,节点JS: var toSend = [ {"id":1, "topic":"Topic1", "name": "Name1"}, {"id":2, "topic":"Topic2", "name": "Name2"} ] app.get('/topics', function(req, res){ return res.json(toSend); }); }); app.get('/newpage/id/:id', function(req,

节点JS:

var toSend = [ 
    {"id":1, "topic":"Topic1", "name": "Name1"},
    {"id":2, "topic":"Topic2", "name": "Name2"}
    ]


app.get('/topics', function(req, res){
    return res.json(toSend);
    });
});


app.get('/newpage/id/:id', function(req, res){
    var theid = req.params.id;
    return res.json(theid);
});
在我的index.html页面中,我有以下内容:

<html ng-app="myApp">
<head>
<script src="angular.min.js"></script>
</head>
<body>
<div ng-controller="Ctrl1">

<ul>
  <li ng-repeat="topic in topics">
       <a ng-href="newpage/id={{topic.id}}"> {{topic.name}} </a>
  </li>
</ul>

</div>
<script src = "myapp.js"></script>
</body>
</html>
在newpage.html中:

//HTML same to index.html. The body is: 
<body>
    <div ng-controller="newpageCtrl">
        {{name}}
    </div>
</body>
//HTML与index.HTML相同。主体是:
{{name}}
在我单击index.html中的
  • 之前,一切正常。我从不使用从Angular
    ng href
    传递的id访问新页面。我想要实现的是在索引页面中显示
    li
    ,当我单击任何链接时,将我带到新页面,并单击id。我似乎无法从节点传递值。如果使用express并定义视图,则可以使用
    传递值。但我想用Angular的模板

    如何将角度页面中单击的值传递给NodeJS,并将页面重定向到另一个具有正确值的角度页面


    谢谢。

    我已经解释了使用angular ui路由器的plunker代码

    也许你可以把它作为一个基础,并在此基础上构建你的样本。”

    在您的Html上:

    <body >
        <ul> 
           <li><a ui-sref="home">Home</a></li>
           <li><a ui-sref="sports">Sports</a></li>
           <li><a ui-sref="country">Country</a></li>
        </ul>
        <div ui-view></div>
    </body>
    
    
    
    • 运动
    • 国家

    布线在角度上的工作方式不同。浏览一下角度布线的概念。Kalyan,谢谢。但是当我也使用Nodejs时,我可以使用角度路由吗?当然可以。在您的例子中,您正在使用NodeJS来实现API。你的前端是有角度的。我尝试使用ng路线,也遵循了该教程。它的静态页面在教程中使用,我想在页面之间进行更改。我想在AngularJS中单击链接时打开一个页面,并将其传递给NodeJS,然后将json值传递给AngularJS页面。我已经尝试了6个多小时了。感谢您分享这篇精彩的文章。关于如何集成nodejs和在页面之间传递变量,我还在挠头。你必须使用$http promise来调用你的node js api。我仍然不知道怎么做。你能给我看一个工作示例吗?我创建了一个restful api,并且能够创建一个CURD应用程序。我现在可以获取/发布/放置/删除这些值。我唯一的问题是,如何在新页面中显示单个条目的值?
    (function(){
    
      'use strict';
    
      angular
      .module('plunker')
      .config(['$stateProvider', function($stateProvider)
      {
          $stateProvider
          .state('home', {
                  url: '/', 
                templateUrl: 'home.html'      
                })
          .state('sports', {
          url: '/sports', 
          templateUrl: 'sports.html'      
          })    
            .state('sports.football', {
            url: '/football', 
            templateUrl: 'football.html'      
            })
            .state('sports.weightlifting', {
            url: '/weightlifting', 
            templateUrl: 'weightlifting.html'      
            })
            .state('sports.swimming', {
            url: '/swimming', 
            templateUrl: 'swimming.html'      
            })
          .state('country', {
          url: '/country', 
          templateUrl: 'country.html'      
          });
    
      }])
      .controller('testCtrl',function(){
    
      });
    
    })();
    
    <body >
        <ul> 
           <li><a ui-sref="home">Home</a></li>
           <li><a ui-sref="sports">Sports</a></li>
           <li><a ui-sref="country">Country</a></li>
        </ul>
        <div ui-view></div>
    </body>