0

I am working through a tutorial for node js and angular. I am new to angular. The problem I am having is. You can navigate throughout the site fine via the client (angular) navbar, but if you type in the url in the browser it becomes a problem because node does not know about the request url. My simple question is. How do you send a node server request to angular?

Please note that I was trying to prevent the catch all app.get('*'). It causes the site to crash. Not sure why. So having two routes is my solution

here is what I am looking for

app.get('/admin/users',function(req,res){
  //This is node. There is already a angular controller that handles this
  //How do I send to angular
  res.send('../../app/public/admin/user-list');//this does not by the way.???
});

Angular route that works fine when navigating through nav bar

$routeProvider.when('/admin/accounts', {
  templateUrl: '/partials/admin/user-list',
  controller: 'mvUserListCtrl', resolve:routeRoleChecks.admin
})
9
  • Access the ../../app/public/admin/user-list response in your $http callback Dec 30, 2015 at 14:06
  • Please put more code.. And what kind of Angular router you're using? (ui-router?) Dec 30, 2015 at 14:15
  • @Daniel_L can you give me an example on the node side how this is complete? I am not quite sure what you mean. Thanks
    – user516883
    Dec 30, 2015 at 14:16
  • @SmartyTwiti just added angular route.
    – user516883
    Dec 30, 2015 at 14:18
  • 1
    it's because angular routes aren't necessarily correlated to routes you define in express. in angular, /partials/foobar is not localhost:8000/partials/foobar, it is localhost:8000#partials/foobar. express isn't receiving the GET request because you aren't activating the correct route. Dec 30, 2015 at 14:36

1 Answer 1

1

Create the resources using app.get(base_url) in node.js and make the resources available at one location now when you hit the resources from angular using http like below

return {
        getServiceData: function () {
            $rootScope.loading = true;
            var req = {
                method: 'GET',
                url: base_url+'patients'
            };

            return $http(req).then(function (result) {
                // alert("data in service = " + JSON.stringify(result.data));
                return result.data;
            });
        }

I think this would be helpful

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.