Angularjs the ' value copying ' and ' reference replication ' in directives using sub-scopes

Source: Internet
Author: User

<!DOCTYPE HTML><HTMLLang= "ZH-CN"Ng-app= "App"><Head>    <MetaCharSet= "Utf-8">    <title>Using sub-scopes in directives</title>    <Linkrel= "stylesheet"href=".. /bootstrap.min.css "></Head><Body>    <h4>A JavaScript object is either a value copy or a reference copy. String, numeric, and Boolean variables are value replication. Arrays, objects, and functions are reference replication. Here's a look at the difference between the two</h4>1. Value Replication<DivNg-controller= "Somecontroller">Initial value:<inputtype= "text"Ng-model= "Somebarevalue"><BR>{{Somebarevalue}}<ButtonNg-click= "someaction ()">Parent scope</Button>             <DivNg-controller= "Childcontroller">{{Somebarevalue}}<ButtonNg-click= "childaction ()">Child scope</Button>             </Div>     </Div>1. Reference Replication<DivNg-controller= "Scontroller">{{Somemodel.somevalue}}<ButtonNg-click= "someaction ()">Parent scope</Button>             <DivNg-controller= "Ccontroller">{{Somemodel.somevalue}}<ButtonNg-click= "childaction ()">Child scope</Button>             </Div>     </Div>         <Scriptsrc=".. /angular.min.js "></Script>    <Script>Angular.module ('app', [])        //Value Replication. Controller ('Somecontroller', function($scope) {$scope. Somebarevalue= "'; //not in favor of it. Declaring data should declare an object in the form of a data model see reference replication$scope. Someaction= function() {$scope. Somebarevalue= 'Hello Human, from parent';         }; }). controller ('Childcontroller', function($scope) {$scope. childaction= function() {$scope. Somebarevalue= 'Hello Human, from child';         }; })        //Reference Replication. Controller ('Scontroller', function($scope) {$scope. Somemodel={somevalue:'Hello computer'             }; $scope. Someaction= function() {$scope. Somemodel.somevalue= 'Hello Human, from parent';         }; }). controller ('Ccontroller', function($scope) {$scope. childaction= function() {$scope. Somemodel.somevalue= 'Hello Human, from child';         };     }); </Script></Body></HTML>

Here I focus on the value copy, reference replication nothing to say

            /* About value replication: Childcontroller is a                        child scope of Somecontroller so take it for granted that when $scope.somebarevalue in a child scope has no initial value,            he replicates the parent scope $scope. Somebarevalue value as its own value, when the value of $scope.somebarevalue in the parent scope changes, it also causes the value of $scope.somebarevalue in the child scope            to change, but when the values in the child scope $scope. Somebarevalue when there is an initial value, the $scope.somebarevalue in the parent scope and the child scope            becomes two completely different things. In            layman's words, when you don't have money in your pocket, The money in your father's pocket is your money, your father has money, you have money, your father has no money, you have no money.            But when you set up a family to earn money for yourself, your father will keep his own money for retirement, will not give you, and your money from the beginning to the end belongs to you!
             Don't be stingy with your money, be nice to your loved ones! 
*/

Angularjs the ' value copying ' and ' reference replication ' in directives using sub-scopes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.