Binding policy in Angularjs "@", "=", "&" instance

Source: Internet
Author: User

<!DOCTYPE HTML><HTMLLang= "ZH-CN"Ng-app= "App"><Head>    <MetaCharSet= "Utf-8">    <title>Binding policy</title>    <Linkrel= "stylesheet"href=".. /bootstrap.min.css "></Head><Body>    <h4>Angularjs provides several ways to bind the internal isolation scope of the directive to the scope outside of the directive. </h4>To make the new instruction scope accessible to variables in the current local scope, you need to use one of the following three aliases (the official explanation below):<ol>        <!--Local Scope Properties: Use the @ symbol to bind the local scope to the value of the DOM property. Directives internal scopes can use variables from external scopes.  -        <Li>@ (or @attr)</Li>        <!--Two-way binding: by = You can make two-way data binding on properties on a local scope's property on the half-level scope. Just like normal data binding, local properties reflect changes that occur in the parent data model.  -        <Li>= (or =attr)</Li>        <!--parent scope bindings through the & symbol, you can bind the parent scope to run the function in it.         means that setting this value generates a wrapper function that points to the parent scope. To invoke a parent method with a parameter, we need to pass an object that is the name of the parameter, and the value is the content to pass to the parameter.  -        <Li>& (or&attr)</Li>    </ol>    <Divstyle= "border:1px solid red;width:400px;height:200px;"Ng-controller= "Parentcontroller">        <Pstyle= "Color:orange;">Please carefully remember the following input boxes in the prompt text</P>You remember? <inputtype= "checkbox"Ng-model= "Isremember">        <PNg-show= "Isremember">            <inputtype= "text"Ng-model= "Someval"placeholder= "Randomly enter several values">and try to change the value of the following two input</P>        <DivNg-show= "!isremember | | someval"my-directive One-val= "{{someval}}"Two-val= "Someval"Three-val= "parentfun (' haha ')"></Div>    </Div>        <Scriptsrc=".. /angular.min.js "></Script>    <Script>Angular.module ('app', []). Directive ('mydirective', function() {            return{restrict:'A', replace:true, scope: {oneval:'@oneVal', //equivalent to "value copy"Twoval:'=twoval', //equivalent to "Reference replication"Threeval:'&threeval' //binding methods in the parent scope}, Template:'<div>'+                            '<input type= "text" ng-model= "Oneval" placeholder= "@ Change me Other not affected" >'+                            '<input type= "text" ng-model= "Twoval" placeholder= "= if you move, I have to change everything else" >'+                            '<input type= "button" ng-click= "Threeval ()" value= "$ point I'll try it" >'+                          '</div>'}}). controller ('Parentcontroller', function($scope) {$scope. Parentfun= function(s) {alert ("I successfully bound a function in the parent scope! " +s); }        })    </Script></Body></HTML>

The above example can be run directly, running more interesting!

Binding policy in Angularjs "@", "=", "&" instance

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.