0
对于角度js(新的一周)来说是新的。我有一个要求是使用$ http发送请求。我想显示在另一个页面中的响应消息中收到的错误,但我无法弄清楚如何将该值传递给另一个页面。控制器新的页面不同于正在进行http调用的页面。下面是我写的代码。似乎没有任何工作。请指导我如何处理这个需求?将错误消息JSON传递给另一个页面模板
$http({
method : 'POST',
url : 'http://localhost:8080/abc/users',
data : JSON.stringify(toPass)
}).then(function (data) {
// this callback will be called asynchronously
// when the response is available
console.log(data.data+'a');
$scope.result="The request has been successfully submitted" +data.data.emailId;
$scope.x=data.data.emailId;
console.log('result'+x);
console.log('result');
//$location.path('/Success?{error1}');
window.location="/Success?{x}";
/*if (data.data.error){
$scope.error=data.data.error
}else{
$scope.result=data.data.emailId;
}*/
}, function (error) {
// called asynchronously if an error occurs
// or server returns response with an error status.
console.log("An error encountered"+error);
var error1=error.status;
// $location.path('/Success?{error1}');
});
}
})
谢谢你的帮助Wasiq。我用你的代码作为基础并创建了一个服务。 – Batman