notifications.html
<div class='block span3 block-head-btn '>
<p class="block-heading"> Notifications</p>
<div class="alert-box-inner">
<div infinite-scroll="pageNotifications()" infinite-scroll-disabled="feedBusy">
<div ng-repeat="notification in notifications" id="notification-{{notification.id}}" class="well alert-tile" >
<div class='row-fluid'>
<div>
<span><a ng-click="showNotificationDetails(notification)" class="news_title">{{notification.subject}}</label></a>
</div>
<div class='span12 map-detail-line'>
{{notification.sender}}
</div>
<div class="span12"><p class="news_date ng-binding pull-left">{{notification.createdAt}}</p> <p class="pull-right subtle-text">ID# {{notification.id}}</p></div>
</div>
</div>
</div>
</div>
<!----------------------------------------------------------->
</div>
<!--notifications end-->
<div class="block span9 block-heading" >Notification content should display here
{{notification.sender}}
</div>
notificationCtrl.js
$scope.feedBusy = false;
var nextPage = 1;
$scope.pageNotifications = function (){
if($scope.feedBusy)return;
//limit the feed to the last 100 notifications until a better implementation is achieved
if($scope.notifications.length > 100)return;
$scope.feedBusy = true;
restApp.getNotificationWithOptions('dummy',['-createdAt'], '1', '10').then(function(data){
if(data == "No notifications found"){
$scope.feedBusy = false;
$scope.feedend = true;
return;
}
var publicNotifications = [];
for(n in data){
var aDate = new Date(data[n].createdAt);
data[n].createdAt = moment(aDate).format('MMMM Do YYYY, h:mm:ss a');
if(typeof(data[n].latitude) != "undefined"){
data[n].containsLatLong = true;
}else{
data[n].containsLatLong = false;
}
$scope.notifications.push(data[n]);
}
$scope.feedBusy = false;
nextPage++;
},function(err){
alert('error fetching more notifications in the feed '+ err);
});
}
//Show single notification details in content area
$scope.showNotificationDetails = function(notification) {
alert(notification.subject);
}
所以在这里我无法在最后一个div中打印{{notification.sender}},我该怎么做? 我希望这是因为ng-repeat在上部div中结束,但我不能在上部div中写入最后一个div,所以如何在最后一个div中访问发送者?
谢谢
答案 0 :(得分:0)
您无法访问ng-repeat外部的通知。
如果您对最后一项感兴趣,可以尝试:
{{notifications[notifications.length -1].sender}}
修改:根据您的评论:
$scope.showNotificationDetails = function(notification) {
$scope.currentNotification = notification
}
然后标记很简单:
<div class="block span9 block-heading" >
{{currentNotification.sender}}
</div>
答案 1 :(得分:0)
如果您要显示特定的发件人,可以将其存储在父作用域中,然后在ng-repeat之后使用它。
访问父范围:$ scope。$ parent
P.S:这通常不赞成,但通常是自定义子指令和控制器。