AngularJS app initiating twice (tried the usual solutions..)

前端 未结 1 1663
-上瘾入骨i
-上瘾入骨i 2021-01-03 16:43

SOLVED:

Resolution here: https://stackoverflow.com/a/29662815/4004456

Batarang Chrome plugin was firing all ng-click actions twic

相关标签:
1条回答
  • 2021-01-03 17:13

    I believe the problem is in the way the app handles during initialization. If you navigate to your application http://example.com/ then your url will be an empty string and trigger the route change. After it fails to resolve it will then hit the otherwise and cause the double route change/initialization.

    Basically if you fire up the route yourself upon load you shouldn't see the double change. You can just inject the $location service and direct there yourself inside of the run assuming you want to start at any one given point. (see the plunk: http://plnkr.co/edit/lTOSYX?p=preview )

    .run(function ($rootScope, $log, $location) {
        $location.path('/');//Add this
        // continue code here
    });
    

    If your controllers are double loading then you probably have other complications such as the double controller declaration/execution issue mentioned in the note (Combating AngularJS executing controller twice).

    0 讨论(0)
提交回复
热议问题