1

Act と Scene の 2 つのデータ型用に 2 つのファクトリを構築しました。私のシーンの更新機能を除いて、すべてが完全に機能します(作成、読み取り、削除は正常に機能します)。私の人生では、シーン更新機能が機能していないものを理解できません。次のメッセージが表示されます。

TypeError: Object function Resource(value){
        copy(value || {}, this);
      } has no method 'update'
    at Object.ScenesUpdateCtrl.$scope.save

私は2つの工場を持っています:

app.factory('ActsService', function($resource) {
  return $resource('/api/acts/:id', {id: '@id'}, {update: {method: 'PUT'}});
});

app.factory('ScenesService', function($resource) {
  $resource('/api/scenes/:id', {id: '@id'}, {update: {method: 'PUT'}});
  $resource('/api/scenes/:actId', {actId: '@id'}, {query: {method: 'GET', isArray: true}});
  $resource('/api/scenes/:actId/:id', {actId: '@actId', id: '@id'}, {get: {method: 'GET'}});
  return $resource('/api/scenes/:actId/:id', {actId: '@actId', id: '@id'}, {delete: {method: 'DELETE'}}); 
});

そして、すべての更新操作を処理するいくつかのコントローラー。

function ActsUpdateCtrl ($scope, $location, $routeParams, ActsService) {
  var id = $routeParams.id
  $scope.act = ActsService.get({id: id})
  $scope.action = "Update"

  $scope.save = function() {
    ActsService.update({id: id}, $scope.act, function() {
      $location.path('/admin/acts')
    })
  }
}

function ScenesUpdateCtrl ($scope, $location, $routeParams, ScenesService) {
  var id = $routeParams.id
  var actId = $routeParams.actId
  ScenesService.get({actId: actId, id: id}, function(resp){
    $scope.scene = resp
    $scope.actId = resp.PartitionKey
        $scope.prev = resp.prev.split(",")
  })
  $scope.scenes = ScenesService.query({actId: actId})

  $scope.action = "Update"

  $scope.save = function() {
    $scope.scene.prev = $scope.prev
    ScenesService.update({id: id}, $scope.scene, function() {
      $location.path('/admin/acts/' + $scope.actId)
    })
  } 
}

Act は機能し、Scene は前述のエラー メッセージをスローします。

4

1 に答える 1

2

理解した。 AngularJS - サービス オブジェクトの作成

それが機能するようにそれを書く方法を見つけました.なぜそれが機能するのかはわかりませんが、機能する限り私は幸せです.

app.factory('ScenesService', function ($resource) {
  return $resource('/api/scenes/:actId/:id', { actId : '@actId', id:'@id' }, {
    update: {method: 'PUT'},
    query: {method: 'GET', isArray: true},
    get: {method: 'GET'},
    delete: {method: 'DELETE'}
  })  
});
于 2013-07-18T22:18:30.850 に答える