Improve this Doc  View Source

$rootScope.Scope

  1. - type in module ng

A root scope can be retrieved using the $rootScope key from the $injector. Child scopes are created using the $new() method. (Most scopes are created automatically when compiled HTML template is executed.) See also the Scopes guide for an in-depth introduction and usage examples.

Inheritance

A scope can inherit from a parent scope, as in this example:

var parent = $rootScope;
var child = parent.$new();

parent.salutation = "Hello";
expect(child.salutation).toEqual('Hello');

child.salutation = "Welcome";
expect(child.salutation).toEqual('Welcome');
expect(parent.salutation).toEqual('Hello');

When interacting with Scope in tests, additional helper methods are available on the instances of Scope type. See ngMock Scope for additional details.

Usage

$rootScope.Scope([providers], [instanceCache]);

Arguments

Param Type Details
providers
(optional)
Object.<string, function()>=

Map of service factory which need to be provided for the current scope. Defaults to ng.

instanceCache
(optional)
Object.<string, *>=

Provides pre-instantiated services which should append/override services provided by providers. This is handy when unit-testing and having the need to override a default service.

Returns

Object

Newly created scope.

Methods

Events

Properties