AngularJs: controller is called twice by using $routeProvider

前端 未结 10 2243
慢半拍i
慢半拍i 2020-12-04 14:43

Module routes:

var switchModule = angular.module(\'switchModule\', []);

switchModule.config([\'$routeProvider\', function($routeProvider) {
    $routeProvid         


        
10条回答
  •  日久生厌
    2020-12-04 15:05

    I had declaration of SomeController for each view partial in a single state. That caused duplicate event firing.

     .state('chat', {
                url: '/',
                views: {
                    'content@': {
                        templateUrl: 'views/chat_wv1.html',
                        controller: 'ChatController'
                    },
                    'form@': {
                        templateUrl: 'views/chat_wv_placeholder.html',
                        controller: 'ViewController'
                    },
                    'sidePanel@': {
                         templateUrl: 'views/sidePanel_wv.html'
                         /* removing this part solved my issue*/
                         /*controller: 'ChatController'*/
                    }
    
                }
            })
    

    Hope this helps some one else.

提交回复
热议问题