Skip to main content
2 of 2
Fixed formatting

Your "BasicResource" resource factory can be greatly simplified:

before:

app.factory("BasicResource", ["$q", "$http", function ($q, $http) {
    var resourceFactory = {
        async: function(type) {
            var d = $q.defer();
            var result = $http.get("/api/" + type).success(function() {
                d.resolve(result);
            });
            return d.promise;
        }
    };
    return resourceFactory;
}]);

after:

app.factory("basicResource", ["$http", function ($http) {
    return {
        get: function(type) {
            return $http.get("/api/" + type)
                .then(function(response) {
                    return response.data;
                });
        }
    };
}]);

You don't need to call the method async because consumers will expect a promise from such a method. Also resource is probably not the best name for a service which only provides get functionality.

Regarding response transformation, there are several ways to do it. Per request, or by registering interceptors with $httpProvider.

Personally, my preference is to avoid $resource entirely as it behaves oddly, transforming a promise into its result for example. $http meets my needs.

Also note that .success and .error are deprecated and you should use .then and .catch in their place. This will improve interop and avoid some quirks.