如何将对象传递给AngularJS工厂?

时间:2015-04-30 20:32:54

标签: javascript angularjs

我处于编辑状态我正在尝试更新riskDto但我收到一些关于某个对象的错误我不知道我做错了请帮忙。

到目前为止已尝试过代码......

ctrl.js

RiskService.saveAllignRiskToProcess($scope.riskDTO,$stateParams.processKey).then(function (response) {
            if ($scope.editMode) {
                $scope.hideYesBtn = true;
                $scope.hideNoBtn = true;
                $scope.showOkBtn = true;
                $scope.messageText = 'Updated Risk Within Process successfully';
                $scope.confirmationWin.open().center();
                $scope.okCallback = $scope.riskAlignToProcessBack;
            }
}
});

facotry.js

saveAllignRiskToProcess: function(processKey) {
        return $http.post('app/risk/rest/riskTocontrol/saveCreateAndAlignNewRiskToProcess/' + processKey);
      }

state.js

.state('createAndAlignRisk', {
                url: '/risk/cnaRsk/:processKey',
                templateUrl: 'views/risk/createNewRisk.html',
                controller: 'RiskCtrl',
                data: {
                    authenticate: true
                }

            })

consoleError

/riskTocontrol/saveCreateAndAlignNewRiskToProcess/[object%20Object]

2 个答案:

答案 0 :(得分:1)

如果要将对象$scope.riskDTO$stateParams.processKey传递给服务,则需要更改服务方法以及调用方法代码

<强>代码

RiskService.saveAllignRiskToProcess($scope.riskDTO,$stateParams.processKey)
 .then(function (response) {
  //..code here 
});

<强>服务

  saveAllignRiskToProcess: function(processKey, riskDTO) {
     var url = 'app/risk/rest/riskTocontrol/saveCreateAndAlignNewRiskToProcess/' + processKey
     return $http.post(url ,JSON.stringify({ 'serverSideParamName': riskDTO}) );
  }

答案 1 :(得分:1)

来自angularjs doc

  

post(url,data,[config]);

     

数据 - 请求内容

您可以从文档中看到Data参数。你错过了:

saveAllignRiskToProcess: function(processKey) {
        return $http.post('app/risk/rest/riskTocontrol/saveCreateAndAlignNewRiskToProcess/' + processKey);
      }