Having an issue with sending URL parameters to a rest method using an angular optimized HTML page.
The code for my rest method is as follows:
router.get("/url/id/:urlid",function(req,res){
var query = "SELECT urlID AS libraryid, "
+ "URL AS libraryitem "
+ "FROM ?? "
+ "WHERE active = 1 "
+ "AND ?? = ? "
whereClause = ['urls', 'urlid', req.params.urlid];
query = mysql.format(query,whereClause);
connection.query(query,function(err,rows){
if(err) {
console.log("Rest Call Error");
res.json({"Error" : true, "Message" : "Error executing MySQL query", "Query" : query});
} else {
console.log("Rest Call Success", rows);
res.json({"Error" : false, "Message" : "Displayed the url "+req.params.urlid, "Query" : query, "URLs" : rows});
}
});
When calling the rest method directly, results are:
{
"Error": false,
"Message": "Displayed the url 5",
"Query": "SELECT urlID AS libraryid, URL AS libraryitem FROM `urls` WHERE active = 1 AND `urlid` = '5' ",
"URLs": [
{
"libraryid": 5,
"libraryitem": "url"
}
]
}
The Controller section includes:
app.controller("UrlByIDController", function ($scope, $http) {
$http.get('/api/url/id/{{urlid}}')
.then(function(data) {
console.log("URl loading", data)
$scope.links = data['URLs'];
})
.catch(function(response) {
console.error('Loading URL error', response.status, response.data);
})
.finally(function() {
console.log("finally finished loading urls");
});
});
For the HTML template:
<div class="form-group">
<label for="txtURL" class="control-label col-xs-3">URL</label>
<div class="col-xs-3" ng-controller="UrlByIDController" >
<input type="text"
id="txtURL"
class="ng-valid ng-dirty"
ng-model="formData.txtURL"
value="{{links.libraryitem}}"
placeholder="URL of Ad" />
</div>
</div>
During debugging, found that the id value passed to the rest method is the phrase 'urlid'. It seems like there might be a basic mistake that I am overlooking.