$new() or $rootScope.new() in angularjs

$new() or $rootScope.new() in angularjs

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 = "[email protected]";//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('[email protected]')) {
    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 = "[email protected]"; //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('[email protected]')) {
    parentRoot.$broadcast("hi, your email is valid!! Thank you!!");
}
else {
    parentRoot.$broadcast("hi, your email is not valid!! Please try again.");
}


ANIL SINGH

Hey! I'm Anil Singh. I author this blog. I'm Active Blogger, Programmer. I love learning new technologies, programming, blogging and participating the forum discussions more...
My Blogs - http://www.code-sample.com and http://www.code-sample.xyz
My Books - Google Amazon and Flipkart Book Store!

You Might Also Like
Post a Comment
www.code-sample.com/. Powered by Blogger.
ASK Questions
SQL Server NodeJs TypeScript JavaScript Angular SQL Server My Book