Angular passing scope to ng-include

Late to the party, but there is a little angular ‘hack’ to achieve this without implementing a dumb directive. Adding a built-in directive that will extend your controller’s scope (like ng-if) everywhere you use the ng-include will actually let you isolate the variable name for all the included scopes. So: <div ng-include=”‘item.html'” ng-if=”true” onload=”item = … Read more

Why form undefined inside ng-include when checking $pristine or $setDirty()?

To understand why the solution with formHolder work you have to understand JavaScript prototypes chain first. Let’s illustrate the first case without formHolder in the following pseudo code: $parentScope = { //I’m a parent scope inside Ctrl2 productForm:{} //to avoid undefined reference error } $childScope = { //I’m a child scope created by by ng-include … Read more

Losing scope when using ng-include

As @Renan mentioned, ng-include creates a new child scope. This scope prototypically inherits (see dashed lines below) from the HomeCtrl scope. ng-model=”lineText” actually creates a primitive scope property on the child scope, not HomeCtrl’s scope. This child scope is not accessible to the parent/HomeCtrl scope: To store what the user typed into HomeCtrl’s $scope.lines array, … Read more