我正在练习角度为$ http的帖子并获得服务,但我的问题是我的回复方法并没有向我发回数据。
这是我的相同
的脚本O(n)
controller.js
'use strict';
angular.module('confusionApp')
.constant("baseURL","http://localhost:8080/app/index.html#/")
.service('menuFactory',['$http','baseURL' function($http,baseURL) {
var dishes=[
{
_id:0,
name:'Uthapizza',
image: 'images/uthapizza.png',
category: 'mains',
label:'Hot',
price:'4.99',
description:'A unique combination of Indian Uthappam (pancake) and Italian pizza, topped with Cerignola olives, ripe vine cherry tomatoes, Vidalia onion, Guntur chillies and Buffalo Paneer.',
comments: [
{
rating:5,
comment:"Imagine all the eatables, living in conFusion!",
author:"John Lemon",
date:"2012-10-16T17:57:28.556094Z"
},
{
rating:4,
comment:"Sends anyone to heaven, I wish I could get my mother-in-law to eat it!",
author:"Paul McVites",
date:"2014-09-05T17:57:28.556094Z"
},
{
rating:3,
comment:"Eat it, just eat it!",
author:"Michael Jaikishan",
date:"2015-02-13T17:57:28.556094Z"
},
{
rating:4,
comment:"Ultimate, Reaching for the stars!",
author:"Ringo Starry",
date:"2013-12-02T17:57:28.556094Z"
},
{
rating:2,
comment:"It's your birthday, we're gonna party!",
author:"25 Cent",
date:"2011-12-02T17:57:28.556094Z"
}
]
} ];
var promotions = [
{
_id:0,
name:'Weekend Grand Buffet',
image: 'images/buffet.png',
label:'New',
price:'19.99',
description:'Featuring mouthwatering combinations with a choice of five different salads, six enticing appetizers, six main entrees and five choicest desserts. Free flowing bubbly and soft drinks. All for just $19.99 per person ',
}
];
this.getDishes = function(){
return $http.get(baseURL+"dishes");
};
this.getDish = function (index) {
return $http.get(baseURL,"dishes/"+index;
};
this.getPromotion=function(index){
return promotions[index];
};
// implement a function named getPromotion
// that returns a selected promotion.
}])
.factory('corporateFactory', function() {
var corpfac = {};
var leadership = [
{
name: "Peter Pan",
image: 'images/alberto.png',
designation: "Chief Epicurious Officer",
abbr: "CEO",
description: "Our CEO, Peter, credits his hardworking East Asian immigrant parents who undertook the arduous journey to the shores of America with the intention of giving their children the best future. His mother's wizardy in the kitchen whipping up the tastiest dishes with whatever is available inexpensively at the supermarket, was his first inspiration to create the fusion cuisines for which The Frying Pan became well known. He brings his zeal for fusion cuisines to this restaurant, pioneering cross-cultural culinary connections."
},
{
name: "Dhanasekaran Witherspoon",
image: 'images/alberto.png',
designation: "Chief Food Officer",
abbr: "CFO",
description: "Our CFO, Danny, as he is affectionately referred to by his colleagues, comes from a long established family tradition in farming and produce. His experiences growing up on a farm in the Australian outback gave him great appreciation for varieties of food sources. As he puts it in his own words, Everything that runs, wins, and everything that stays, pays!"
}
];
corpfac.getLeaders=function(){
return leadership;
}
corpfac.getLeader=function(index){
return leadership[index];
}
return corpfac;
})
;
我正在使用tomcat 8发布此内容。我读到$ http需要json数据我需要以这种方式发送数据吗?
我得到这样的错误:
'use strict';
angular.module('confusionApp')
.controller('DishDetailController', ['$scope', '$stateParams', 'menuFactory', function($scope, $stateParams, menuFactory) {
menuFactory.getDish(parseInt($stateParams.id,10));
$scope.dish ={};
.then(
function(response){
$scope.dish=response.data;
$scope.showDish=true;
}
);
}])
.controller('IndexController',['$scope','menuFactory','corporateFactory',function($scope,menuFactory,corporateFactory){
$scope.promotion=menuFactory.getPromotion(0);
$scope.leader= corporateFactory.getLeader(3);
$scope.feturedDish={};
// $scope.dish = {};
menuFactory.getDish(0)
.then(
function(response){
$scope.feturedDish = response.data;
$scope.showDish = true;
console.log($scope.feturedDish)
}
);
console.log($scope.feturedDish)
}])
.controller('AboutController',['$scope','corporateFactory',function($scope,corporateFactory){
$scope.leaders=corporateFactory.getLeaders();
}])
;
答案 0 :(得分:0)
如果你有你的功能(响应),我会添加errorcallback,因为更有可能在调用中出现问题并且你忽略了错误信息。
menuFactory.getDish(0)
.then(
function(response){
$scope.feturedDish = response.data;
$scope.showDish = true;
console.log($scope.feturedDish)
},
function(reason) {
console.log('Error: ' + JSON.stringify(reason));
}
);
为您的所有getDish调用执行此操作,您更有可能会看到错误。请发布错误,我们可以尝试提供帮助。
答案 1 :(得分:0)