문제

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?

도움이 되었습니까?

해결책

$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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top