Playサーバーを呼び出してJSONオブジェクトを取得する角度サービスがあります。以下は私のコードスニペットです。
service.js
angular.module('testApp.services',[]).factory('testService',function($resource){
var service = {
getData : getData
};
function getData(){
return $resource('http://localhost:9000/testRead',{}, {
save: {
method: 'POST',
headers: {
'Auth-Token': 'B1016693LCAP8154'
}
}
});
};
return service;
});
controller.jsコントローラで
angular.module('testApp.controllers',['testApp.services']).controller('TestController',function($scope, testService){
testService.getData().save().$promise.then(function(data){
$scope.output = angular.fromJson(JSON.stringify(data));
console.log("Output : ", $scope.output);
});
});
、私はtestService.getData().query().$promise.
を使用する場合、すべてが正常に動作します。
Error: [$resource:badcfg] Error in resource configuration
私はプレーからJSON型を返す午前:私はtestService.getData().save().$promise.
にそれを変更した場合でも、それはエラーがスローされます。私はsave()がオブジェクトを期待し、Array()型をクエリしていることを読んでいますか?それはなぜそれ以来働いていないのですか?ブラウザでチェックインすると、レスポンスのJSONデータが取得されていますが、コントローラでは使用できません。下の写真をご覧ください。
エラー:ブラウザで
応答:
ありがとう@Tran。あなたが正しいです。 –