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
});
});
});
panel
次のコントローラーを使用したディレクティブがあります。
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);
});
}
すべてが初めて完全に機能します。ただし、コントローラーが変更されると、のような問題がTypeError: Cannot read property '$$childHead' of null
発生しますが、エラーが発生する可能性があります。
問題は$scope.$on
. $scope を破棄する前に (コントローラーが変更されたとき)、これを削除するにはどうすればよいですか?