Question

I am using CakePHP as my backend.

Therefore, if I use $http, I need to have the following:

a) the default config must be

angularApp.config(function ($httpProvider) {
  $httpProvider.defaults.headers.common['Content-Type'] = 'application/x-www-form-urlencoded';
  $httpProvider.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
  $httpProvider.defaults.headers.common['Accept'] = 'application/json';
  $httpProvider.defaults.transformRequest = function(data) {
      if (data === undefined) {
          return data;
      }
      return $.param(data);
  }
});

b) the ng-model attribute in the html input must be of the pattern

ng-model="data.User.email"

In other words, data.{CakePHPModelName}.{modelattribute}

My $http is working perfectly with the CakePHP backend.

How do I use the angular $resource to be just as successful?

Was it helpful?

Solution

$resource uses $http to make all the requests. Any config you want to do on $http would be done the same way as if you were using only $http.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top