【发布时间】:2015-05-06 06:50:24
【问题描述】:
我是一个氛围和 Angular 新手,我真的很难找到答案!也许我问错了问题。
我正在使用 Atmosphere 设置通知。如果我将 API URL 直接发布到浏览器中,我可以打开 websocket 并观察更新。
在 Angular 中,我有一个 ng-repeat 循环,我希望在每次新更新都会向 websocket 添加一个新对象时运行它。
<li ng-repeat="notification in notifications track by $index">
我正在使用 angular watch 来检查更新,但它不会拾取添加到数组中的新对象。这是我的代码:
// notification alerts
$scope.notifications = [];
notificationsService.notificationAlerts().then(function success(response) {
var jsonStringArray = response.data.split('|');
$scope.notifications = $.map(jsonStringArray, function(n, i){
if (n !== ""){
return JSON.parse(n);
}
});
console.log('Connect', response);
});
$scope.$watch('notifications', function(newVal, oldVal){
console.log('Watch', $scope.notifications);
}, true);
希望我已经说清楚了,如果我需要详细说明,或者我问错了问题,请告诉我。谢谢!
【问题讨论】:
标签: angularjs websocket atmosphere