gpt4 book ai didi

javascript - 无法读取 Angular JS 中未定义的属性成功

转载 作者:行者123 更新时间:2023-11-29 17:57:16 26 4
gpt4 key购买 nike

在 Controller A 中,我有一个方法可以在单击提交按钮时将数据存储在 MVC Controller 操作方法中。

$scope.groupmembership.submit = function() {
if ($scope.groupMembershipUserInputForm.$valid) {
$scope.groupmembershipUploadParams = {
"chapterCode": $scope.groupmembership.chapterCode,
"createdDate": $filter('date')(new Date($scope.groupmembership.createdDate), 'MM/dd/yyyy'),
"endDate": $filter('date')(new Date($scope.groupmembership.endDate), 'MM/dd/yyyy')
};

UploadDataServices.getGroupMembershipUploadParams(
$scope.groupmembershipUploadParams)
.success(function (result) {
$rootScope.$emit(
'validateUploadedFilesEvent',
$scope.groupmembershipUploadParams
);
});
}
}

UploadDataServices.getGroupMembershipUploadParams

getGroupMembershipUploadParams: function(uploadParams){
$http.post(BasePath + "uploadNative/setGroupMembershipUploadParams", uploadParams, {
headers: {
"Content-Type": "application/json",
"Accept": "application/json"
}
}).success(function (result) {
console.log(result);
})
},

上传NativeMVC Controller

public async Task<JsonResult> setGroupMembershipUploadParams(GroupMembershipUploadParams arg)
{
TempData["GroupMembershipUserUplaodDetails"] = arg; //Save the data for later use
var result = new JsonResult();
result.Data = "Success"; // Return a Excel Upload Limit Exceeded
result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
return result;
}

我想在后续调用中由 MVC Controller 中的其他方法重新使用这个保存的数据。

我不想返回任何响应,只是确保在保存 MVC 中的数据后执行 Angular 中的 methodB(),我确实在获得成功响应后触发了一个事件

UploadDataServices.getGroupMembershipUploadParams(
$scope.groupmembershipUploadParams)
.success(function (result) {
$rootScope.$emit('methodB', $scope.groupmembershipUploadParams);
});

我知道 MVC 创建中的这个 result.data 是冗余

var result = new JsonResult();
result.Data = "Success"; // Return a Excel Upload Limit Exceeded
result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
return result;

但是如何确定

$rootScope.$emit('methodB', $scope.groupmembershipUploadParams);

仅在存储 tempData 后触发。

UploadDataServices.getGroupMembershipUploadParams(
$scope.groupmembershipUploadParams)
.success(function (result)

向我抛出错误。有什么可以做得更整齐?我知道有很多冗余代码行。

提前致谢。

最佳答案

如果您的方法中没有return,它将返回undefined。这就是您收到错误的原因。

固定:

getGroupMembershipUploadParams: function(uploadParams){
return $http.post(
BasePath + "uploadNative/setGroupMembershipUploadParams",
uploadParams,
{
headers: {
"Content-Type": "application/json",
"Accept": "application/json"
}
})
.success(function (result) {
console.log(result);
});
},

关于javascript - 无法读取 Angular JS 中未定义的属性成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37991276/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com