AngularJS Directive scope?

0 votes
44 views
asked Jun 22 in AngularJS by admin (8,115 points)
HI All

  what is mean in angualrjs Directive scope?

3 Answers

0 votes
answered Jun 22 by anonymous

SCOPE: FALSE

   This is the default value of scope in the directive definition. In this case, the directive has the same scope as its parent controller.

SCOPE: TRUE

   In this case, the directive has the OWN scope 
0 votes
answered Jun 22 by anonymous

SCOPE: {}

This is how the directive gets its isolated scope. We pass an object for the scope field in this case. This way, the scope of the directive is not inherited from the parent and is instead completely detached from it. Thus, the directive has an isolated scope.

There are 3 types of prefixes in AngularJS:

  1. ‘@’ – Text binding / one-way binding
  2. ‘=’ – Direct model binding / two-way binding
  3. ‘&’ – Behavior binding / Method binding
0 votes
answered Jun 23 by anonymous

Scope False: sample code

  • Creating an Angular app and controller

    var movieApp = angular.module("movieApp",[]);

    movieApp.controller("movieController",function($scope){

        $scope.movie = "Ice Age";

    });

  • Defining the directive

    movieApp.directive("movieDirective", function(){

        return {

            restrict: "E",

            scope: false,

            template: "<div>Movie title : {{movie}}</div>"+

            "Type a new movie title : <input type='text' ng-model='movie' />"

        };

    });

  • Finally, embedding the directive in HTML

    1

    2

    3

    4

    5

    6

    7

    <div ng-app="movieApp">

        <div ng-controller="movieController">

            <h2>Movie: {{movie}}</h2>

      Change Movie Title : <input type='text' ng-model='movie'/>

            <movie-directive></movie-directive>

        </div>

    </div>

...