The Root Scope is creating by using the $rootScope.
Example code.
The below example going to show how to create the root scope
using $rootScope.
var parentRoot = $rootScope;
parentRoot.Email
= "anil.singh@gmail.com";//assign the email value.
//Used
to check the parent email is equal to the given email.
//If
return true then broadcast to "hi, your email is valid!! Thank you!!"
//If
return true then broadcast to "hi, your email is not valid!! Please try
again."
if (expect(parentRoot.Email).toEqual('anil.singh@gmail.com')) {
parentRoot.$broadcast("Hi, your email is valid!! Thank you!!");
}
else {
parentRoot.$broadcast("Hi, your email is not valid!! Please try
again.");
}
The Child scopes are creating by using the $new() method.
The most of the scopes are created automatically at the time
when compiled & executed to HTML page.
If you want to remove the scope from the hierarchy that time
we using to $destroy() method.
Example code.
The below example going to show how to create the child root
scope using $rootScope or parent scope.
var parentRoot = $rootScope;
var childRoot = parentRoot.$new();//Used the new method to get the child root.
childRoot.Email
= "anil@code-sample.com"; //Assign to child root email.
//Used
to check the child email is equal to the given emails.
//If
return true then broadcast to "hi, your email is valid!! Thank you!!"
//If
return true then broadcast to "hi, your email is not valid!! Please try
again."
if (expect(childRoot.Email).toEqual('anil@code-sample.com')) {
parentRoot.$broadcast("hi, your email is valid!! Thank you!!");
}
else {
parentRoot.$broadcast("hi, your email is not valid!! Please try
again.");
}