我正在使用 AngularJS,但找不到解决此问题的方法:
我的控制器有一部分:
$scope.$on('showMoreNotifications', function (event) {
$.ajax({
url: '/notifications',
data: {
notificationCount: 30
},
success: function (e) {
$scope.notifications = e.Messages;
}
});
});
这是使用此控制器的html:
<div class="widget" id="widget-notifications" ng-controller="NotificationsCtrl">
<span class="title" ng-click="$parent.$broadcast('showMoreNotifications')">@*showMoreNotifications()*@
Notifikace
</span>
<div class="messages">
<div ng-repeat="item in notifications" class="message-item type-{{item.Entity}}" data-id="{{item.AuditLogId}}">
<span class="type"></span>
<div class="description">
<span class="date">{{item.Date}}</span> / {{item.Message}}
</div>
</div>
</div>
</div>
如果我单击顶部的 span 类标题,控制器将正确调用服务器并接收 JSON 数据。不幸的是,不要刷新与之关联的 html。当我第二次单击时,html 会从第一个请求中刷新数据。