0

I am using express to route pages, instead of angular-route (I am developing a web app that utilizes angular, node, sequelize, and express). So far the routing has worked excellently with angular, and all is fine. However, now I am passing a parameter into the url, and I want to utilize that on destination page to filter results by this parameter. Unfortunately, instead of a filtered list based on the parameter, I just get all clients on the page. Here is a fraction of my express.js:

app.get('/client/:id', routes.clientpage, function(req, res) {
var id = req.param('id');
res.send(id);
console.log('req.param('id')');
}
);

} Here is the page that I am trying to use this parameter "id" on:

<!DOCTYPE html > 
<html ng-app="app">
<%include header3%>
<%include navbar%>
<div ng-controller="ClientCtrl">
<div ng-repeat="client in clients | filter:{id:id} ">
<header><a href="/about" class="btn btn-primary">Back to clients</a>  <h2>{{client.name}}</h2> <small> <span style="padding-left:463px">Staff: {{client.staff}} </small> </header>
<h1><span style="padding-left:300px"><a href="/client/{{client.id}}" class="btn btn-primary">Personal</a>
<a href="/client/{{client.id}}/ci" class="btn btn-primary">Case Info</a>
<a href="/client/{{client.id}}/i" class="btn btn-primary">Insurance</a>
<a href="/client/{{client.id}}/m" class="btn btn-primary">Medical</a>
<a href="/client/{{client.id}}/f" class="btn btn-primary">Financial</a></h1>
<body>
<div class="container">
<div ng-controller="ClientCtrl">
<div class="datagrid"><table>  
<thead> 
<tr> 
 <th> ID </th>
 <th> Phone </th>
 <th> Address </th>
 <th> Zip </th>
 </tr>
 </thead>
 <tbody>
 <tr ng-repeat="client in clients | orderBy:'id' | filter:{id:id} | limitTo: 1">
 <td>
 {{client.id}}
 </td>
 <td> <input type="text" ng-model="client.phone" value="{{client.phone}}"/> </td>
 <td><input type="text" value="{{client.address}}"/></td>
 <td><input type="text" value="{{client.zip}}"/></td>
 </tr>
 <tr> 
 <thead>
 <th> SSN </th>
 <th> Age </th>
 <th> DOB </th>
 <th> DLN </th>
 </thead>
 </tr>
 <tr ng-repeat="client in clients | filter:{id:id} | orderBy:'id' | limitTo: 1">
 <td> <input type="text" value="{{client.ssn}}"/> </td>
 <td><input type="text" value="{{client.age}}"/</td>
 <td><input type="text" value="{{client.birthday}}"/></td>
 <td><input type="text" value="{{client.dln}}"/></td>
 </tr>
</tbody>
</table>
</body>
5
  • "I am using express to route pages, instead of angular-route " You can't use express on the client side... You have to use an angular router. Commented May 19, 2016 at 17:40
  • When I try to route with angular-route, it doesn't direct to the proper page. Furthermore, what are they accomplishing in this tutorial scotch.io/tutorials/learn-to-use-the-new-router-in-expressjs-4 ? Commented May 19, 2016 at 17:42
  • The link is about backend route mate (node). Commented May 19, 2016 at 17:45
  • I see -- well, if I am using express to match a url with a page, how can I catch the parameter with angular-route ? I have tried to no avail. Commented May 19, 2016 at 17:46
  • There was nothing wrong with what he said. It is implied that if he is using express instead of angular he is using server side instead of client side routing. He did not said he was using express for client side routing. It is not an important distinction to make relative to his question. Commented May 19, 2016 at 17:47

2 Answers 2

1

The right way to catch GET params is like this :

app.get('/client/:id', routes.clientpage, function(req, res) {
  var id = req.params.id;
  res.send('id : ' + id);
  console.log(id);
});
Sign up to request clarification or add additional context in comments.

8 Comments

tried this, however I am receiving no results indicating that is properly doing as intended.
did you make sure that you're giving the hand to the middleware from the routes.clientpage, i mean byt executing the next() function ?
No, I did not. I am new in this area, and unfortunately I do not have knowledge of what you have mentioned. Will you please elaborate?
well, in the end of the routes.clientpage you need to add this line next() also make sure that the callback function is having three parametres : req,res,next so that you d't get hit by next is not defined .
Here is my routes.clientpage 'exports.clientpage= function(req, res,next) { next(); res.render('clientpage', { title : 'WAV' }); };' Is this the correct handling ?
|
0

Instead of this:

var id = req.param('id');

Try this:

var id = req.params.id;

I think the way you did it has been deprecated.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.