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, 2020 in Angular by anonymous
• 37,520 points
1,250 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, 2020 by Niroj
• 82,840 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, 2020 in Angular by Niroj
• 82,840 points
1,345 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, 2020 in Angular by Niroj
• 82,840 points
1,045 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, 2020 in Web Development by Niroj
• 82,840 points

edited Jan 21, 2020 by Niroj 1,144 views
+1 vote
1 answer

What is css box module?

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

answered Jan 20, 2020 in Web Development by Niroj
• 82,840 points

edited Jan 21, 2020 by Niroj 1,206 views
0 votes
3 answers

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

display:none means that the tag in question will ...READ MORE

answered Dec 14, 2020 in Web Development by Gitika
• 65,770 points
119,702 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, 2020 in Web Development by Niroj
• 82,840 points

edited Jan 21, 2020 by Niroj 2,971 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, 2020 in Angular by Niroj
• 82,840 points
649 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP