javascript - Reload a single resource when it has changed in Angular? -
i have bit of predicament. make use of notification feature on our angular
site, , obvious reasons notification changes occasionally.
i reload element/div
that displays notification, when notification changes.
to accomplish this, know 1 have clear cache of item, or force refresh or reload of item, bit stuck in regard. don't want clear entire cache accomplish this, , not sure route follow. insight on this.
below <div>
displays notification (this part of larger page):
<div id="notificationbox" class="{{current.type}}" ng-controller="currentnotificationcontroller" ng-hide="hidenotification"> <img src="images/close.svg" height="15" width="15" title="close notification" class="closeicon" ng-click="closenotification()" /> <img src="images/info-icon.svg" height="20" title="ornico notification" /> <span class="notificationtext" ng-bind-html="current.message"></span> </div>
below controller handles notifications:
(function () { 'use strict'; angular.module('portaldashboardapp') .controller('currentnotificationcontroller', ['$http', '$scope', '$sce', '$sessionstorage', function ($http, $scope, $sce, $sessionstorage) { $http.get('notification/notification.txt') .success(function (data) { formatnotification(data); }) .error(function (error, status) { console.error('error reading notification.json, error: ' + error + ' status: ' + status); }); function formatnotification(notification) { $scope.current = { type: notification.type, message: $sce.trustashtml(notification.message) }; } $scope.closenotification = function () { $scope.hidenotification = true; $sessionstorage.notificationopen = false; }; if (angular.isdefined($sessionstorage.notificationopen)) { if ($sessionstorage.notificationopen === false) { $scope.closenotification(); } } }]); })();
below example of notification.txt
:
{ "message": "test1", "type": "notifyinfo" }
Comments
Post a Comment