1

From what I read, the most common cause of this problem is when the controller is included in the template and in the route provider. In my case, only the parent template containing this html is being included in the router, and has its own controller. The sub-templates are being included as a result of a menu selection

So, whenever the menu item is selected, the template gets loaded in, and everything in the controller executes twice. Can it be a product of the the ng-switch or ng-include?

<span ng-switch on="selection">
    <div ng-switch-when="0">
        <div ng-include="'partials/one.html'" ng-controller="oneController"></div>
    </div>
    <div ng-switch-when="1">
        <div ng-include="'partials/two.html'" ng-controller="twoController"></div>
    </div>
    <div ng-switch-when="2">
        <div ng-include="'partials/three.html'" ng-controller="threeController"></div>
    </div>
</span>

Edit:

The included partials do not include the controller again. I've triple checked that these controllers are not mentioned anywhere other than this piece of code. The contents of the one/two/three partials look like this, and the controller still runs twice.

<div>Nothing to see here.</div>
2
  • 1
    I made a plunkr with the details you provided but I cannot seem to duplicate your results. plnkr.co/edit/r8DrDIYENCOw0xZ8lZyu. Can you check if I am missing anything? Commented Mar 31, 2014 at 20:26
  • Perhaps add a $watch to selection and log out its value when it changes. Commented Mar 31, 2014 at 20:31

1 Answer 1

1

I am making an educated guess here... but does your "'partials/one.html'" also have a ng-controller="oneController" in it? If so, you either need to remove the ng-controller declaration from your include div or from your partial.

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

1 Comment

It does not. I understand that the most common way that this error comes up is when the controllers get nested by accident.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.