Thursday, 18 May 2017

How to use $ http.get () of angularjs 1.6 with url with parameters

I'm using nodejs and angularjs but I do not understand how to get the data from nodejs to angular, I'll leave my code here

App.js angular

Var myApp = angular.module ('angularTodo', ['angularUtils.directives.dirPagination']);


MyApp.controller ('mainController', ['$ scope', '$ http', function ($ scope, $ http) {

   $ Http.get ('/ api / all'). Then (function (res) {
       $ Scope.pacientes = res.data;

       $ Scope.sort = function (keyname) {
               $ Scope.sortKey = keyname; // set the sortKey to the param passed
               $ Scope.reverse =! $ Scope.reverse; // if true make it false and vice versa
           }
   }). Finally (function () {
       $ Scope.example7 + = "(Finally called)";
   });


}]);

MyApp.controller ('patient', ['$ scope', '$ http', function ($ scope, $ http)

   $ Http.get ('/ patient /: id') .then (function (res) {
       $ Scope.new = res.data.pk;
       $ Scope.test = "test11";
   }). Finally (function () {
       $ Scope.example7 + = "(Finally called)";
   });


}]);

Routes.js

App.get ('/ patient /: id', function (req, res) {

Var id = req.params.id;

Connection.query ('SELECT * FROM patient WHERE pat_id =?', [Id], function (err, data)
        {

            If (err)
                Console.log ("Error Selecting:% s", err);

            Res.json (data [0]);
            Console.log (id);
            Console.log (data);

         });



});

App.get ('/ newinf /: id', isLoggedIn, function (req, res) {

     Res.render ('informe.ejs', {user: req.user});

});

The problem is that $ http.get ('/ patient /: id') is not receiving the id? How do I get the id of the url in angularjs?



via M. Node

No comments:

Post a Comment