I have a case where I need to nest controllers. I do not want the child scope to inherit from the parent scope because I have scope variables with the same names in both controllers. Is there a way to do this?
I am trying to prevent the childController's variable from being updated when the parentController's variable is changed.
<div ng-controller="parentController">
{{myVariable}}
<div ng-controller="childController">
{{myVariable}}
</div>
</div>
I am aware that I can change the name of the child controller's scope variable to avoid the inheritance problem completely, but I am looking for an alternative. Is there any known way to do this?
Kind of like isolating the scope of a directive, but isolated or private controller scope.
Edit: I have discovered that the child controller will inherit the parent controller scope var value when there is no default value for that var set in the child controller.
Compare: http://jsfiddle.net/4qcqdb6z/ to http://jsfiddle.net/4qcqdb6z/2/
controller as
syntax (docs.angularjs.org/api/ng/directive/ngController), but I dislike it personally. – JB Nizet Aug 14 at 19:43