AngularJS Live Example
HTML
<div ng:app>
Enter some text: <input type="text" name="input" ng-model="text" ng-model-instant>
<button ng-click="childScope.$destroy()">Suspend child scope</button>
<button ng-click="childScope.$reconnect()">Resume child scope</button>
<div ng-controller="ChildCtrl">
Child-Scope: {{text}}
</div>
</div>
CSS
</style>
<script src="http://docs-next.angularjs.org/angular-1.0.0rc2.min.js"></script>
<style>
.ng-invalid { border: 1px solid red; }
body { font-family: Arial,Helvetica,sans-serif; }
body, td, th { font-size: 14px; margin: 0; }
table { border-collapse: separate; border-spacing: 2px; display: table; margin-bottom: 0; margin-top: 0; -moz-box-sizing: border-box; text-indent: 0; }
a:link, a:visited, a:hover { color: #5D6DB6; text-decoration: none; }
.error { color: red; }
JavaScript
var ng = angular.module('ng');
ng.run(['$rootScope', function($rootScope) {
var _$destroy = $rootScope.$destroy;
$rootScope.$destroy = function() {
this.$$destroyed = true;
return _$destroy.apply(this, arguments);
};
$rootScope.$reconnect = function() {
var child = this;
if (child===$rootScope) {
// Nothing to do here.
return;
}
if (!child.$$destroyed) {
return;
}
child.$$destroyed = false;
// See Scope.$new for this logic...
child.$$prevSibling = $rootScope.$$childTail;
if ($rootScope.$$childHead) {
$rootScope.$$childTail.$$nextSibling = child;
$rootScope.$$childTail = child;
} else {
$rootScope.$$childHead = $rootScope.$$childTail = child;
}
}
}]);
function Ctrl($scope) {
$scope.text = 'guest';
$scope.word = /^\w*$/;
}
function ChildCtrl($scope) {
$scope.$parent.childScope = $scope;
}