Angularjs: Controller is called multiple times

后端 未结 4 1361
我寻月下人不归
我寻月下人不归 2021-01-12 13:59

For some reason, my controller is double called, when I switch between resource 1 and resource2.

Here\'s the code:

index.html



        
4条回答
  •  旧巷少年郎
    2021-01-12 14:16

    one another solution which worked for me is that if you defined a directive, try not set its controller to the one which is calling multiple times, just add the directive to your app by using app.directive.

        app.directive('myDirective',[ '$window', function ($window) {
        function link(scope, element) {
               // stuff
            });
        };
    
        return {
          restrict: 'A',
          scope: {offset: "@"},
          link: link,
          // controller: myCtrl //myCtrl was called multiple I comment this line
        };
      }]);
    

提交回复
热议问题