嗨,我正在使用 Web api 作为前端做 angularjs 应用程序。每当某些用户没有特定权限时,我都会将 Httpresponsemessage 返回为
var message = string.Format("You do not have permission");
HttpError err = new HttpError(message);
return Request.CreateResponse(HttpStatusCode.NotFound, err);
我想以 Angular 提醒上面的消息,我正在尝试如下。
$scope.Update = function () {
var servCall = ProjectSetting_Service.update(sub);
servCall.then(function (data) {
alert(JSON.stringify(data));
});
}, function (error) {
//How to alert message here
}
我可以在这里得到一些帮助吗?任何帮助,将不胜感激。谢谢。
最佳答案
在 html 中添加一个 View 并在错误中显示该 View 试试这个
$scope.showError = false;
$scope.Update = function () {
var servCall = ProjectSetting_Service.update(sub);
servCall.then(function (data) {
alert(JSON.stringify(data));
});
}, function (error) {
//alert message
$scope.showError = true;
}
在你的html中
<div ng-show="!showError ">
<p> Everything is going fine :)</p>
</div>
<div ng-show="showError ">
<p> 404 sorry</p>
</div>
关于javascript - 如何在angularjs中显示错误消息(404),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42158118/