Uncaught SyntaxError: Unexpected token using $ http.get ()

0

I am trying to get a list through a url using the GET method, but it generates a very confusing error, since it is the first time I see it.

Uncaught SyntaxError: Unexpected token .

He tells me that I have the error in the next line

grupos.$inject = ['$http'];

function grupos($http){

    function obtenerGrupos(){

        var url;

        url = 'http://localhost:1890/Grupos1';

        return {
            $http.get(url);
        };

    };

    return {
        obtenerGrupos: obtenerGrupos
    };

}

According to the editor that I use, VS Code, it tells me that I have to put two points : instead of a point . . And if I place to try to see what happens, tell me this.

Uncaught SyntaxError: Unexpected token ;

    
asked by Pedro Miguel Pimienta Morales 29.10.2017 в 23:03
source

1 answer

2

It is very obvious the error, you are returning an object return {...} , you can not enter ; within an object because it is not a valid syntax, each field-value is separated by comma. You also lack the literal

return {
    nombre: $http.get(url)
//  ^^^^^^ esto  
}
    
answered by 30.10.2017 / 01:42
source