Skip to content

$http.get and posts #52

@Simone-Zabberoni

Description

@Simone-Zabberoni

Api access from angular to the backend is used like that:

(from authService.js):

return $http.post('/api/authenticate', {
			username: username,
			password: password
		})
			.then(function(data) {
				AuthToken.setToken(data.token);
       			return data;
			});

Try to login and data.token is undefined.
I've checked online and i found that $http.post returns a response object which contains the data object.

I've had to rewrite authService like that:

	return $http.post('/api/authenticate', {
			username: username,
			password: password
		})
			.then(function(response) {
				AuthToken.setToken(response.data.token);
       			return data;
			});

Log in again and response.data.token is now defined.

The same issue affects all api routes: if you fix authService you can log in but the users view is empty

To fix it, modify userCrtl.js from

User.all()
		.then(function(data) {
			// when all the users come back, remove the processing variable
			vm.processing = false;

			// bind the users that come back to vm.users
			vm.users = data;
		});

to:

User.all()
		.then(function(response) {
			// when all the users come back, remove the processing variable
			vm.processing = false;

			// bind the users that come back to vm.users
			vm.users = response.data;
		});

Still need to patch the other views.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions