如何在angularjs中显示错误消息(404)

Nir*_*ole 0 javascript angularjs

嗨,我正在使用web api作为前端的angularjs应用程序.每当某个用户没有某些权限时,我就会将Httpresponsemessage作为

var message = string.Format("You do not have permission");
                        HttpError err = new HttpError(message);
                        return Request.CreateResponse(HttpStatusCode.NotFound, err);
Run Code Online (Sandbox Code Playgroud)

我想以角度提醒上面的消息,我正在尝试如下.

$scope.Update = function () {
        var servCall = ProjectSetting_Service.update(sub);
        servCall.then(function (data) {
            alert(JSON.stringify(data));
            });
    }, function (error) {
//How to alert message here

    }
Run Code Online (Sandbox Code Playgroud)

我可以在这里得到一些帮助!任何帮助,将不胜感激.谢谢.

Sau*_*wal 5

在html中添加一个视图,并在错误中显示该视图试试这个

$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;    
    }
Run Code Online (Sandbox Code Playgroud)

在你的HTML中

<div ng-show="!showError ">
    <p> Everything is going fine :)</p>    
</div>
<div ng-show="showError ">
    <p> 404 sorry</p>
</div>
Run Code Online (Sandbox Code Playgroud)