Answer the question
In order to leave comments, you need to log in
How to make a module in Angular.js?
In addition to my previous question
So, there is a service that pulls data with messages, with certain data (read - satus1, not read - status2).
(function () {
'use strict';
angular
.module('app.notifications')
.factory('notificationService', notificationService);
notificationService.$inject = ['$resource'];
function notificationService($resource) {
return $resource('server/json/notifications.json', {}, {
getNotificationsData: {method: 'GET', isArray: true}
});
}
}());
(function () {
'use strict';
angular
.module('app.core')
.controller('HomeController', HomeController);
//Underscore в зависимости
HomeController.$inject = ['notificationService', '_'];
function HomeController(notificationService, _) {
var vm = this;
vm.showNotificationList = false;
vm.unreadNotifications = [];
vm.readNotifications = [];
activate();
// Получаем данные и отправляем их в SplitNotifications (разделяем на прочитанные и нет)
function activate() {
return getNotifications().then(function () {
SplitNotifications(vm.showNotificationList);
});
} ;
// Получаем данные из сервиса
function getNotifications() {
return notificationService.getNotificationsData()
.$promise.then(function (data) {
vm.showNotificationList = data;
return vm.showNotificationList;
});
}
;
// Разделяем данные, полученные из сервиса на два массива - прочитанных сообщений и не прочитанных
function SplitNotifications(showNotificationList) {
for (var i = 0; i < showNotificationList.length; i++) {
vm.unreadNotifications = _.filter(showNotificationList, {status:'1'});
vm.readNotifications = _.filter(showNotificationList, {status:'2'});
}
}
} ;
})();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question