0

Suppose I have index.html which has mainCtrl as its controller. If I use an ng-include in index.html to include partial html code that is saved on a separate page, does the included page have the mainCtrl or do I need to specify it again on that page?

1
  • If including it inside element which has mainCtrl then yes it will automatically share parent scope (mainCtrl), otherwise no. Commented Jun 14, 2016 at 14:36

3 Answers 3

1

If including it inside element which has mainCtrl then yes it will automatically share parent scope (mainCtrl), otherwise no.

Sign up to request clarification or add additional context in comments.

Comments

0

mainCtrl and it's scope will be also available in your included part.

2 Comments

Not always true. If the ng-include is not inside an element referencing the controller, then the controller won't be available in the included template.
@wdanda "Suppose I have index.html which has mainCtrl as its controller. If I use an ng-include in index.html to include partial html code.." in index.html , that has mainCtrl as it's controller
0

ngInclude Directive

Directive Info

This directive creates new scope.

You can also find a good example in the below link.

Source: https://docs.angularjs.org/api/ng/directive/ngInclude

Comments