search

Home  >  Q&A  >  body text

angular.js - angular如何在url里传递参数?

在做一个小爬虫,先爬了一个列表,再根据每一个href去爬文章

我在href里将新的url参数传递

<ion-item ng-repeat="item in news" class="item item-icon-left">
     <a href="#/app/newslist/{{item.href}}" >

在ionic的路由里是这样写的:

url: "/newslist/:url",

我希望将url这个参数传给node写的server,
ionic的controller是这样传参数的

.controller('SingleNewsCtrl', function ($scope,$stateParams,$http) {
    $http.get('http://localhost:3000/newslist/' + $stateParams.url)
        .success(function(data){
            $scope.title = data.title;
            $scope.date = data.date;

在server里,希望接受url参数,再去爬新的页面

app.get('/newslist/:url', function (req, res) {
var url = req.params.url;

superagent.get(url)
    .end(function (err, data) {
        if (err) console.log(err);

但是url总是接受不到,不知道angular里的传参哪里写错了,希望大家指点下~~

黄舟黄舟2743 days ago592

reply all(1)I'll reply

  • 大家讲道理

    大家讲道理2017-05-15 16:53:32

    I think your ionic routing statement and node processing are not right. ionic uses ui-router. If your parameter is a path, you can use it directly:

    javascripturl: "/newslist/:url",
    

    is wrong, the route defining path type should be as follows:

    javascripturl: "/newslist/{path:.*}"
    

    or:

    javascripturl: "/newslist/*path"
    

    Similarly, in the router of node, the statement accepting the request should not be correct. Usually: name does not support url type parameters. You need to check the router component document you are using and solve it by yourself.

    reply
    0
  • Cancelreply