gpt4 book ai didi

javascript - Angular : How to send the data to service

转载 作者:行者123 更新时间:2023-11-29 23:46:43 25 4
gpt4 key购买 nike

在下面的代码中,我成功地获得了 $scope.hero.rating 中的评级和 $scope.hero.order 中的订单,现在我想将这两个传递给服务作为 Hero 对象指向在 OrderService 类中定义的 OrderService.ratingHero ,当我这样做时

OrderService.ratingHero($scope.hero).then(函数(响应)

它给我一个错误 500...有人帮我解决这个问题吗?

'use strict';
angular.module('Orders').controller('RatingHeroCtrl',['$scope','$state', '$ionicModal', 'MessageService', 'SettingService', 'OrderService','UserService',

function($scope, $state, $ionicModal, MessageService, SettingService,OrderService,UserService) {
$scope.heroName = "Danish";
(function initialize(){
$scope.hero = {};
$scope.rider = {
ratingsObject : {
iconOn: 'ion-ios-star', //Optional
iconOff: 'ion-ios-star-outline', //Optional
iconOnColor: 'rgb(200, 200, 100)', //Optional
iconOffColor: 'rgb(200, 100, 100)', //Optional
rating: 0, //Optional
minRating: 0, //Optional
// readOnly: ratingReadOnly, //Optional
callback: function(rating, index) { //Mandatory

$scope.ratingsCallback(rating,index);
}
}
}
})()
$scope.ratingsCallback = function(rating, index) {

$scope.hero.rating = rating;

OrderService.getOrder($state.params.orderId,
function(response) {
$scope.hero.order = response;
console.log("order"+$scope.hero.order);
},
function(error){
console.log("error");


}
)
}]);

OrderService.js

angular.module('Orders')
.service('OrderService', ['$http', '$state', '$resource', '$q', 'SettingService', '$localStorage', "MessageService",
function($http, $state, $resource, $q, SettingService, $localStorage, MessageService) {
var orderResource = $resource(SettingService.baseUrl + "api/orders/:id", {id:'@id'}, {'query':{method:'GET', isArray:false}, 'update':{method:'PATCH'}});
var service = {
ratingHero : function(hero){
return $http({
method: "POST",
url: SettingService.baseUrl + "api/heroRatings",
data: hero
});
},

getOrder : function(OrderId, successCallback, failureCallback){
orderResource.query({id:OrderId}, successCallback, failureCallback);
}
}
return service;
}]);

最佳答案

错误 500 表示您的服务器端有错误:

500 Internal Server Error
A generic error message, given when an unexpected condition was encountered and no more specific message is suitable.

由于这是一条非常通用的消息,因此可能存在多种可能的问题,但该问题并非来自您的 AngularJS 代码。

我建议您检查您是否在 Angular 中正确拼写了您的服务器名称/API,并查看您的服务器日志,寻找异常/崩溃/错误。

关于javascript - Angular : How to send the data to service,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43734187/

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