0

For some reason , I am not able to hit the controller post my routing logic is called. Though I have envent handlers to track the routing, I dont see any message being printed in the console logs. Please can you guide me here?

ROUTING

angular
    .module('icebergApp')
    .config(setupRouting);

setupRouting.$inject = ['$stateProvider', '$urlRouterProvider'];

function setupRouting($stateProvider, $urlRouterProvider) {
    $urlRouterProvider.otherwise("/iceberg-ui");
    $stateProvider
        .state('iceberg.reconlist', {
            url: "/iceberg-ui",
            templateUrl: "app/iceberg/reconlist/reconlist.view.html",
            controller: 'ReconListController as vm'
        })


}
}());

angular.module('app').run(setupRoutingEventListeners);

setupRouting.$inject = ['$rootScope'];

function setupRoutingEventListeners($rootScope) {
        $rootScope.$on('$stateChangeStart',function(event, toState, toParams, fromState, fromParams){
        console.log('$stateChangeStart to '+toState.name+'- fired when the transition begins. toState,toParams : \n',toState, toParams);
    });
    $rootScope.$on('$stateChangeError',function(event, toState, toParams, fromState, fromParams, error){
        console.log('$stateChangeError - fired when an error occurs during transition.');
        console.log(arguments);
    });
    $rootScope.$on('$stateChangeSuccess',function(event, toState, toParams, fromState, fromParams){
        console.log('$stateChangeSuccess to '+toState.name+'- fired once the state transition is complete.');
    });
    $rootScope.$on('$viewContentLoading',function(event, viewConfig){
        console.log('$viewContentLoading - view begins loading - dom not rendered',viewConfig);
    });

    $rootScope.$on('$stateNotFound',function(event, unfoundState, fromState, fromParams){
        console.log('$stateNotFound '+unfoundState.to+'  - fired when a state cannot be found by its name.');
        console.log(unfoundState, fromState, fromParams);
    });
   }

CONTROLLER

(function() {
    'use strict';

    var myApp = angular.module('iceberg.reconlist');
    myApp.controller('ReconListController', ReconListController);

    ReconListController.$inject = ['ReconListService'];

    function ReconListController(ReconListService) {
        var vm = this;
}
}());

MODULE

(function() {
    'use strict';

    angular.module('icebergApp', [
               'ui.router',
        'iceberg.reconlist'
    ]);

    angular.module('iceberg.reconlist', [
    ]);    
}());
8
  • Did you check for errors? Commented Apr 28, 2017 at 10:16
  • I am not getting errors, and that is why I added above event listeners. What i notice is none of the even listeners are getting called, I don't see any fromState or toState when I put my debugger on to it during the breakpoint. Commented Apr 28, 2017 at 10:17
  • Have you imported the controller into your routing file? Commented Apr 28, 2017 at 10:20
  • I have set the dependency in the modules, iceberg.reconlist module is passed to icebergApp module. I guess that should be enough. What do you mean by importing controller into routing file (angular 1.5), can you please elaborate? Commented Apr 28, 2017 at 10:22
  • 1
    your routing code is in a module called app, but it doesn't seem to have any reference to icebergApp or visa versa. Commented Apr 28, 2017 at 10:34

2 Answers 2

1

you define module by

angular.module('icebergApp', []);

and later you have used

angular.module('app').run(setupRoutingEventListeners);

that is the main issue.

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

1 Comment

Sorry, its a copy paste error, It is icebergApp not App. I have corrected it . In my code it is icebergApp, just to confirm, but the issue still persists. – alice 48 mins ago
0

change

    controller: 'ReconListController as vm'

to

    controller: 'ReconListController'

1 Comment

I don't think that helps. You can use 'Controller as aliasname' with the controller name. I have used it before and that works fine.

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.