What is inherited/child scope in directive?

0 votes
Is directive inheritance having the same concept as of controller inheritance? can someone please explain me with an example?
Feb 5 in Angular by anonymous
• 10,760 points
28 views

1 answer to this question.

0 votes

Hey kartik,

As you use the term inheritance so its common that some class use the property of other class.

If you want the difference between controller inheritance and directive inheritance you can first refer to my  controller inheritance explanation.

so, Directive inheritance also use the same concept of  controller inheritance but the only difference is that we can explicitly allow the parent scope data to be inherited to its child  scope.

Now. the question arise how can we have option to inherit data from parent scope? For this let us consider a sample piece of code as example is best way to explain!!

html code

<body ng-app="app">

     <div id='div1' ng-controller="sample">

          a={{a}}, b={{b}}

         <div message></div>

   </div>

</body>

Here, the controller sample has a directive contain in it named as "message". The directive is defined as under:

Directive code

app.directive('message',function(){

return{

         templateUrl:'info_msg.htm'

         scope:true

      }

}
We can see from above code that we use extra parameter called "scope:true" which enable the directive named message to inherit data from its parent scope.

However ,if we use Scope:false then the directive message having created its own scope under its parent scope but doesn't inherit any data from its parent.

If there is any change in the child scope those are not reflected in the parent scope. To do this we can use the same method $parent.data=New_value(same as controller inheritance).

answered Feb 5 by Niroj
• 21,680 points

Related Questions In Angular

0 votes
1 answer

What is shared scope(in Directive)?

Assuming that you have knowledge on Scope( ...READ MORE

answered Feb 4 in Angular by Niroj
• 21,680 points
29 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

What is Scope Parameter in AngularJS?

Hey @kartik, Scope Parameter is a collection of ...READ MORE

answered Feb 5 in Angular by Niroj
• 21,680 points
50 views
+1 vote
1 answer

What is the relationship between angularjs Scope with controller/view?

Let us consider the below block: <div ng-controller="emp"> ...READ MORE

answered Jan 20 in Web Development by Niroj
• 21,680 points

edited Jan 21 by Niroj 67 views
+1 vote
1 answer

What is css box module?

Hey, All the element present in html follows ...READ MORE

answered Jan 20 in Web Development by Niroj
• 21,680 points

edited Jan 21 by Niroj 53 views
0 votes
1 answer

Explain the difference between visibility:hidden; and display:none?

hii, visibility:hidden; and display:none are totally different used ...READ MORE

answered Jan 20 in Web Development by Niroj
• 21,680 points
349 views
+1 vote
1 answer

How to access the Angularjs scope of a particular html element from our console?

Hello, You should follow the below steps:-- 1.Compile and ...READ MORE

answered Jan 21 in Web Development by Niroj
• 21,680 points

edited Jan 21 by Niroj 52 views
0 votes
1 answer

What is inherited/child Scope in Controller?

hii, As you know(if not refer  ) that scope ...READ MORE

answered Feb 5 in Angular by Niroj
• 21,680 points
20 views
0 votes
1 answer