-2

I am getting "ReferenceError: success is not defined" when doing a Restful call from controller to my node.js back end as follows:

authControllers.js:

authControllers.controller('authCtrl', ['$scope', '$location', '$window', 'UserService', 'AuthenticationService',
function authCtrl($scope, $location, $window, UserService, AuthenticationService) {
  $scope.me = function() {    
    UserService.me(function(res) {
      $scope.myDetails = res;
    }, function() {
      console.log('Failed to fetch details');
      $rootScope.error = 'Failed to fetch details';
    })
  };      
}]);

html:

<div class="row" data-ng-controller="authCtrl" data-ng-init="me()">
    <div class="col-lg-12">
        <div class="panel panel-primary">
            <div class="panel-heading">
                <strong>Your Details</strong>
            </div>
            <div class="panel-body">
                <p>{{myDetails.data.username}}</p>
                <p>{{myDetails.data.email}}</p>
            </div>
        </div>
    </div>
</div>

authServices.js:

authServices.factory('UserService',['$http', function($http) {
  return {        
    me:function() {
    return $http.get(options.api.base_url + '/me').success(success).error(error)
    }
  }
}]);

A successful nodeJs call is being received and it's returning data as well, but couldn't get it in the front end. Please help !

4
  • 1
    you should have search this in the google rather than SOF Commented Jun 8, 2017 at 11:20
  • I had searched but I not get any particular result. Commented Jun 8, 2017 at 11:21
  • @NarendraSolanki there are dozens of articles about this in the web. Also youtube video which explain it step by step. Commented Jun 8, 2017 at 11:23
  • Well google search fetched me this link of SO. check it out. success not defined Commented Jun 8, 2017 at 13:56

3 Answers 3

2

I was starting a detailed explanation on PHP + Angular in order to solve that issue when I found that post detailing everything way better than me.

Please have a look : https://stackoverflow.com/a/39654288/3687474

Sign up to request clarification or add additional context in comments.

Comments

1

You cannot connect to mongo directly from the angular application, you can use nodejs to connect to the mongodb and fetch data. Go through the following link,

NODE TODO LIST APP WITH MONGODB

Comments

1

There's no way to access any DB from any framework that has been developed in javascript you need to have a server if you want to perform CURD operations first go through nodejs if you want server to be written in JS then you can go through rest calls in nodejs that will help you to develop your app.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.