angular.js - How to pass parameters in url in angular?
黄舟
黄舟 2017-05-15 16:51:32
0
1
629

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~~

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(1)
大家讲道理

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template