I came across this code snippet
.state('fooState', {
url: '/foo',
templateUrl: 'path/to/bar.html',
controller:'parentController'
})
// Here's the content of bar.html
<div class="sample">
<div ng-show="bazinga" ng-controller="child1Controller">
<!-- some cool stuff -->
</div>
<div ng-show="!bazinga" ng-controller="child2Controller">
<!-- more cool stuff -->
</div>
</div>
I have a question, is it expected behavior that when the first div
with the child1Controller
controller is displayed, the child2Controller
will still execute? How can I prevent a controller from executing if its corresponding div
is hidden using ng-show="false"
? My goal is to have only the parentController
and the child1Controller
active when the first div
is visible. Similarly, when the second div
is visible, only the parentController
and the child1Controller
should be active.