0

I was wondering, how could this be written in angularJS?

requests: {
    fetchUsers: function() {
        return {
            url: 'https://www.example.com/api/v2/users',
            type: 'GET',
            username: '[email protected]/token',
            password: 'myAPItoken'
        };
    }
}

1 Answer 1

2

This is just an example:

Your controller:

var userCtrl = angular.module('UserCtrl',[]);

    userCtrl.controller('UserController',function($scope,Users){
        var getUsers = Users.fetchAll();
            getUsers.then(function(response){
               $scope.users = response;
            });
    });

Your service:

var userSrvc = angular.module('UserSrvc',[]);

userSrvc.factory("Users",function($http){

    return{
        fetchAll: function(){
            var request = $http({method:'GET', url:'https://www.example.com/api/v2/users'});
            return request;
        }
    }
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.