S
S
Sergey2019-09-11 12:37:50
JavaScript
Sergey, 2019-09-11 12:37:50

How to return a DB response in AngularJS?

Good afternoon. Wrote a function for a service in AngularJS that makes a request to the database. I can't figure out how to make the function return the data value. In my case below, the value is undefine, which is logical because not the function itself, but the resolved request promise returned data. How to correctly change the function, so that as a result it itself would return data. Thanks in advance.

function getData($http) {

        this.users = function(){
        $http.get('http://localhost:3000/getUsers')
                .success(data=>{
                   return data})                    
        }
    }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question