I am trying to refresh every new page that AngularJS loads as follows:
Controller:
angular.module('adsomaApp')
.controller('BrandsController', function ($window) {
var vm = this;
vm.init = function() {
$window.location.reload();
};
});
View
<div class="container" ng-controller="BrandsController as vm" ng-init="vm.init()">Test</div>
Strangely, this causes the page to reload indefinitely. It gets stuck in a loop. Any idea how I can get it to reload once on route change?
I think the cause of the problem is here:
'use strict';
/**
* @ngdoc directive
* @name adsomaApp.directive:resize
* @description
* # resize
*/
angular.module('adsomaApp')
.directive('resize', function () {
return function (scope, $window) {
var w = angular.element($window);
scope.getWindowDimensions = function () {
return {
'h': screen.height,
'w': window.innerWidth
};
};
scope.$watch(scope.getWindowDimensions, function (newValue) {
scope.windowHeight = newValue.h;
scope.windowWidth = newValue.w;
scope.youtubeBgVideoStyle = function () {
return {
'max-width': '1000%',
'margin-left': '0px',
'width': newValue.w + 'px',
'min-height': '100vh',
'height': newValue.h + 'px',
'margin-bottom': '-50%'
};
};
}, true);
w.bind('resize', function () {
scope.$apply();
});
w.bind('load', function () {
scope.$apply();
});
};
});
How do I trigger this directive refresh on route change?