我對ng-show有個令人沮喪的問題,那就是它不能與功能同步工作,就像它被完全忽略一樣。我試圖在ng-repeat元素中顯示按鈕,它基於來自控制器的函數返回true/false。在控制器Angular ng-show與功能不同步
功能代碼:
$scope.isRated = function(reservation){
var reservationID = reservation.id;
var guestEmail = $rootScope.USER.email;
var json = JSON.stringify({
"reservationID": reservationID,
"guestEmail": guestEmail.toString(),
"venueRating": $scope.foodRating,
"restaurantRating":$scope.restaurantRating,
"serviceRating":$scope.serviceRating
});
var url = "http://localhost:9900/api/reservation/isRated";
$.ajax(
{
type: 'POST',
url: url,
contentType: "application/json",
data : json,
success: function (response) {
// alert(response + " " + reservationID);
return response;
},
error: function (err) {
console.log(err);
}
}
);
HTML格在它應該出現:
<p>{{USER.name}}</p>
<div class="row" ng-init="loadData()">
<div class="col-md-4">
<label>Passed reservations</label><br/>
<div ng-repeat="x in restaurantHistory track by x.id">
{{x.id}} {{x.restaurant.name}} <button ng-show="isRated(x)" ng-click="rateReservation(x)" class="btn btn-link">Rate</button>
<hr>
</div>
<hr>
<a href="#advanced">Advanced settings</a>
<br/>
</div>
</div>
功能工作正常,返回布爾通緝,但我不能設法找到一種方法將其與html中的按鈕元素進行連接。我嘗試了其他問題上的一切,但迄今爲止沒有運氣。沒有報告的錯誤,它只是不工作,因爲它應該。
非常感謝,解決了我遇到的一個問題! – Lupus