artch/angular-route-segment

Child controller is getting loaded twice

Closed this issue · 1 comments

I have my top level menu which is driven by mainctrl. I then click on the home link when it linked to my homectrl. However the home ctrl is getting loaded twice every time I click on it. My debug statements look like thus:

Inside main controller. mainCtrl.js:2
Location change start: http://localhost:51537/client/index.html#/home/198 app.js:250
Route change start: {"params":{"siteId":"198"},"pathParams":{"siteId":"198"}} app.js:258
Route changed to: {"params":{"siteId":"198"},"pathParams":{"siteId":"198"},"locals":{}} app.js:266
Route segment change inside main controller. mainCtrl.js:8
Inside home controller. homeCtrl.js:2
Inside home controller. homeCtrl.js:2
Home view content loaded. homeCtrl.js:37
Main view content loaded.

You can see the statement "Inside home controller" is happening twice. This is just a console log statement that I have as the first line of my controller. I'm thinking my controller code for the view should only run once. Am I missing something? This happens anytime I switch from one second level view to another.

This was my fault. I didn't realize if you use the ng-controller attribute and also specify a controller in the route that it would cause the controller to get executed twice.