I have created a custom directive in AngularJS. The code is as follows:
var esscom = angular.module('esscom',['ngMaterial' ,'ngMessages','ui.bootstrap','ui.router']);
esscom.directive('resize',[function($window){
return function($scope){
console.log("Inside resize dir");
angular.element($window).bind('resize', function() {
console.log("Window resize");
if( $window.innerWidth <= 960){
console.log("Returning ess background");
angular.element("#view").addClass('essbackground');
}
$scope.$apply();
})
};
}]);
The HTML is as follows:
<div resize id="view">
<h1>Resize this</h1>
</div>
This just doesn't work. The resize event is never detected. Am I doing anything wrong?