I am learning directive module of Angular.js and how to create your own diectives.
I am reading a book "Mastering AngularJS Directives by Josh Kurz".
Here I went though one example, but didn't understood much.
This is the code below,
<!DOCTYPE html> <html lang="en" ng-app="MyApp"> <head> <title>Recipe 02 example 01</title> <script type="text/javascript" src="D:\Rahul Shivsharan\JavaScript-Framework\AngularJS\angular.js"></script> <script type="text/javascript" src="D:\Rahul Shivsharan\JavaScript-Framework\jQuery\jquery-1.11.1.js"></script> <script type="text/javascript" src="D:\Rahul Shivsharan\JavaScript-Framework\BootstrapCSS\bootstrap-3.2.0-dist\js\bootstrap.js"></script> <link rel="stylesheet" href="D:\Rahul Shivsharan\JavaScript-Framework\BootstrapCSS\bootstrap-3.2.0-dist\css\bootstrap.css"></link> <link rel="stylesheet" href="D:\Rahul Shivsharan\JavaScript-Framework\BootstrapCSS\bootstrap-3.2.0-dist\css\bootstrap-theme.css"></link> <script type="text/javaScript"> angular.module("MyApp",[]); (function(){ angular.module("MyApp").controller("myCtrl",myCtrl); angular.module("MyApp").directive("bbString",bbString); angular.module("MyApp").directive("bbTwoString",bbTwoString); angular.module("MyApp").directive("bbExpression",bbExpression); function myCtrl($scope){ $scope.actorName = "Jim Carry"; }; function bbString(){ var obj = { scope : { name : "@abbraKaDabraa" }, template : "<input ng-model='name' />" } return obj; }; function bbTwoString(){ var obj = { scope : { name : "=theName" }, template : "<input ng-model='name' />" } return obj; }; function bbExpression(){ var obj = { scope : { term : "&" }, template : "<input ng-model='term' />", link : function(scope,element,attrs){ scope.term = scope.term(); } } return obj; } })(); </script> </head> <body ng-controller="myCtrl"> <div class="container"> <div class="well"> <div bb-string abbra-ka-dabraa="{{actorName}}"></div> <p><b>{{actorName}}</b></p> <div bb-expression term="newTerm = actorName + ' Some Extra content'"></div> <br/> <div bb-two-string the-name="actorName"></div> </div> </div> </body> From the above example you can see,
I have created three directives "bb-string", "bb-two-string" and "bb-expression".
After reading the book, what I understood is all the directives are having defining scope.
What I understood from the the term defining scope is that "The scope which a directive gets from its parent directive".
So whether I understood properly, or is it that the directive "bb-string" has an isolate scope, and the directive "bb-two-string" has a defining scope. ?
If all the directives are using "defining scope" so are these scope inherited from controller "myCtrl" scope ?
And last questing,
the directive "bb-expression" has a code,
scope.term = scope.term(); what does "scope.term()" mean, were does the term function came from ?
this is the link for the live example.