Just learning the MEAN stack at the moment, and I'm fiddling around with it but I'm a little lost.
What I'm trying to achieve is to utilize an external API to auto fill input fields about the tag that is initially typed.
So the question is, how do I pass the value of foo all the way to server.js for the call?
- End-user enters a
tagand presses 'Get Data' - Controller passes the value of
tag(defined in my.ejsfile asng-model="object.tag") to thegetDataroute server.jstakestagand passes it into the external API URL to call- External API does its thing, returns with a nice and pretty
JSONfile for me. - Controller auto populates as many form fields as it can from the returned JSON.
Here are a few code bits just so you understand the structure of what I have a little more:
--index.ejs--
<input type="text" ng-model="object.tag" />
<button ng-click="grabFooInfo()">Get Data</button>
--controller.js--
$scope.grabFooInfo = function(){
$http.get('/getData').success(function(res){
// Will do stuff here after data comes back
});
};
--server.js--
app.get('/getData', function (req, res) {
var options = {
host: 'my.api.im.calling.com,
path: '/v1/fooApi/' + // #Need foo here //
headers: {
accept: "application/json"
},
method: 'GET'
};
var req = https.request(options, function (response) {
var fooData = '';
response.on('data', function (data) {
fooData += data;
});
response.on('end', function () {
res.send(fooData);
});
});
req.on('error', function (e) {
console.log('problem with request: ' + e.message);
});
req.end();
});
- Am I doing my routing properly for how Node is intended to work?
- How do I pass an input value to this internal function in
server.jsusing Angular?
