I have a simple app built with AngularJS:
var App = angular.module('myApp', [], function($window) {
// settings..
}).run(function($rootScope){
$(window).on('resize', function(event) {
$rootScope.$broadcast('windowResize',{
height: event.target.innerHeight,
width: event.target.innerWidth
});
});
});
I have a directive, panel, with the following controller:
function($scope, $element) {
var
$title = $element.find('.panel-title'),
$content = $element.find('.panel-content'),
margin = 20
;
$content
.height($(window).height() - $title.height() - margin);
$scope.$on('windowResize', function(obj) {
var height = obj.height - $title.height() - margin;
$content.height(height);
});
}
All works perfectly the first time. When the controller changes, however, I get problems like TypeError: Cannot read property '$$childHead' of null, but I can get the error.
The problem is with $scope.$on. How can I remove this before destroying the $scope (when the controller changes)?
$destroyevent may be useful.