search

Home  >  Q&A  >  body text

angular.js - How to pass parameters in url in angular?

I am making a small crawler, first crawl a list, and then crawl articles based on each href

I pass the new url parameters in href

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

This is what is written in ionic’s routing:

url: "/newslist/:url",

I hope to pass the url parameter to the server written in node,
This is how ionic’s controller passes parameters

.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;

In the server, I hope to accept the url parameters and then crawl a new page

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

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

But the url is always not accepted. I don’t know where the parameters in angular are written wrong. I hope you can give me some advice~~

黄舟黄舟2809 days ago632

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