Angular Directive scope

Source: Internet
Author: User

Angular Directive scope

1. When the scope attribute is not specified in directive, the directive directly uses the scope of the app;

2. When you specify the scope attribute in directive, there are 3 ways to scope scope:

2.1. =: Represents the data bidirectional binding, as long as the property changes, the value of scope in the app (that is, the parent scope) and the corresponding value in the directive will change simultaneously;

2.2. @: Represents the data one-way binding, the change of the value only affects directive, does not affect the app (that is, the parent scope) other values, that is, the orphaned scope;

2.3. &: Represents a method that inherits or uses a scope binding in the parent scope.

Here is a demo to illustrate:

Example

Directive HTML:

<gmb-per say= "Myalert ()" abc= "Gmbpernotification_d" >gmb-per</gmb-per>

Coffee Directive Code:

# module

Angular.module (' demo ', [])
. Controller ' Myctrl ', ($scope),

$scope. Gmbpernotification_d = [+]
$scope. Myalert =
Alert (11)

#directive

Pushnotificationapp.directive ' Gmbper ', ($timeout, $compile)Restrict:' AE '#terminal:truetransclude:true#replace:trueTemplate:' <div class= ' col-lg-4 chartwrap "ng-click=" Say () "ng-repeat=" Pern in abc ">121212</div>"#replace:trueSCOPE:ABC:=Gmbpernotification_d:=say:' & 'Controller: ($scope)-# $scope. MyTest= [] Link: (scope, Element, Attrs)-Console.log

Angular Directive scope

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.