我正在做一個$ http呼叫,在呼叫之後,我得到錯誤響應,其中 被顯示在視圖上,我可以在控制檯日誌中看到錯誤消息,但是它的 沒有顯示在視圖上。 我在$範圍分配錯誤信息給一個變量和內插 上查看
下同是$ HTTP調用
userService.getUser = function(searchByNum){
var q = $q.defer();
$http({
method:'GET',
url :'http://localhost:8083/simpro1/helloRest/user/'+searchByNum
}).success(function(response){
userService.user=response;
q.resolve(response);
}).error(function(error){
userService.errors = error;
q.reject(error);
})
return q.promise;
}
下面的服務部分的控制器部分
$scope.getDetails = function(searchByNum){
userService.getUser(searchByNum)
.then(function(res){
console.log(res);
},function(error){
**$scope.errMessages = userService.errors.errMessage;**
})
}
在上述錯誤代碼塊中,將消息分配給變量$ scope.errMessages ,但在視圖上沒有更新,但在控制檯上可以看到錯誤消息 。
能有人幫我這個請....
下面是認爲其{{errMessages}}變量
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<title>Jumbotron Template for Bootstrap</title>
<body ng-controller="contactHomeCtrl">
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div>
<a class="navbar-brand" href="#">{{username | capitalizeFirstLetter }}</a>
</div>
</div>
<div id="navbar" text-align="right" class="navbar-collapse collapse">
<a class="navbar-brand" href="#" ng-click="logout()">Logout</a>
</div>
<div> </div>
<!-- Main jumbotron for a primary marketing message or call to action -->
<div class="jumbotron">
<div class="container">
<h1>U R Fired</h1>
<p>This is a template for a simple marketing or informational website. It includes a large callout called a jumbotron and three supporting pieces of content. Use it as a starting point to create something more unique.</p>
<p>
<div has-permission = "['administration', 'ROLE_ADMIN']">
<a class="btn btn-primary btn-lg" ui-sref="#" role="button">Learn more »</a>
</div>
</p>
</div>
</div>
<div class="container">
<!-- Example row of columns -->
<div class="row">
<div class="col-md-4">
<h5>Enter the Number to Search</h5>
<div ui-view="contactByNumber"></div>
</div>
<div class="col-md-4">
**<div>{{errMessages}} </div>**
</div>
<div class="col-md-4">
<div></div>
</div>
<hr>
<footer>
</footer>
</div> <!-- /container -->
</body>
</html>
console.log("error message"+userService.errors.errMessage); results in
No Customer is found with Id
console.log("error Object"+JSON.stringify(error)); results in complex object
with all the html messages this is also a failure message
向我們展示您的視圖,並檢查服務$ http –
中的'console.log(userService.errors.errMessage)'和'console.log(error)'不要使用'.success()'和' .error()'在你的服務中。他們已被棄用。還要記住,在服務的'.success()'函數中,'response'變量保存* data *,而不是整個響應。 – cst1992
在哪個控制器中定義了'$ scope.getDetails = function(searchByNum){}'函數?它在'contactHomeCtrl'上嗎? –