Reputation: 52
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>
Upvotes: 0
Views: 663
Reputation: 1169
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);
});
Upvotes: 1
Reputation: 642
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.
Upvotes: 0