huan feng
huan feng

Reputation: 8623

What's the difference between $rootScope.$new() and $rootScope.$new(true)?

Can anyone help to understand the difference between $rootScope.$new() and $rootScope.$new(true) ? As per my understanding, they should be the same, since $rootScope doesn't have a parent scope.

Upvotes: 3

Views: 1232

Answers (1)

tasseKATT
tasseKATT

Reputation: 38490

The first parameter of $new decides whether the new scope shall be isolated or not.

Consider the following:

$rootScope.data = { property: 'Value' };

var childA = $rootScope.$new();

var childB = $rootScope.$new(true);

childA will not be isolated and will have access to data due to prototypal inheritance.

childB will be isolated and will not inherit from $rootScope (actually it can still access data via the $parent property, but that is another issue).

Upvotes: 8

Related Questions