0

I am facing problem in call to controller in child ui state router.

URL is changing but controller not call.

no console error*

Please check code:

HTML

<a style="cursor: pointer;" class="btn btn-default btn-xs"  ui-sref="interactions.details({id:n.id})">Detail</a>

Router

.state('interactions', {
            url: '/interactions',        
            data: {
                pageTitle: 'Interaction',
                IsLoginPage: false
            },
            templateUrl: '../../modules/interaction/views/interaction.html',
            controller: 'interactionCtl'
        })
        .state('interactions.details', {
            url:'/details/:id',
            data: {
                pageTitle: 'Interaction Details',
                IsLoginPage: false
            },
            templateUrl: '../../modules/interaction/views/interactionDetail.html',
            controller:'interactionCtlDetails'
        }).run(function ($rootScope, settings, $cookies, $http, $location, AuthenticationService, $state, $stateParams) {

    $rootScope.$state = $state;
    $rootScope.$stateParams = $stateParams; 

});

Controller

    warApp.controller('interactionCtlDetails', ["$scope", '$rootScope','$stateParams', 'settings', 'categoryService', 'blockUI',
        function ($scope, interactionService, $rootScope, $stateParams ,settings, categoryService, blockUI) {

            var id = $stateParams.id;
console.log(id);

    });
2
  • It would be helpful for others wanting to help to have a working sample of code snippet or jsbin/jsfiddle/codepen sample. Commented Apr 2, 2017 at 4:13
  • yeah, this will be helpful. Thank you, Commented Apr 2, 2017 at 4:15

4 Answers 4

1

Annotation array should be in sync with the parameters in the function declaration.Here annotation array is not in sync with the parameters in the function declaration.

Second parameter in your annotation array is 'interactionService' but in function, thats 'rootScope'.

Try with below controller code

warApp.controller('interactionCtlDetails', ['$scope', '$rootScope', '$stateParams', 'settings', 'categoryService', 'blockUI',
function ($scope, $rootScope, $stateParams ,settings, categoryService, blockUI) {
        var id = $stateParams.id;
        console.log(id);
});
Sign up to request clarification or add additional context in comments.

Comments

1
 warApp.controller('interactionCtlDetails', ["$scope", '$rootScope','$stateParams', 'settings', 'categoryService', 'blockUI',
        function ($scope, interactionService, $rootScope, $stateParams ,settings, categoryService, blockUI) {

      var id = $stateParams.id;
       console.log(id);
    });

In above code you have function ($scope, interactionService, $rootScope, $stateParams ,settings, categoryService, blockUI) where you have interactionService which you have missed in your injection section

Comments

0

Simpler example of routing, maybe you can narrow down the problem by adding one controller at a time and build the rest. Fiddle or error will help.

angular.module('myApp').config(function ($stateProvider){

    $stateProvider
        .state('form', {
        url:"/form",
            views:  {
                "listColumn": { 
                     templateUrl: "/form1.html",
                     controller:'myController1'
                  },
                "formColumn": {
                      templateUrl: "/form2.html"
                  } 
            }
        })  
});

Comments

0

Definitely your controller should throw an error in console, the order of dependency parameters injected in the controller is wrong, you are missing interactionService

change it as,

warApp.controller('interactionCtlDetails', ["$scope", 'interactionService','$rootScope','$stateParams', 'settings', 'categoryService', 'blockUI',
        function ($scope, interactionService, $rootScope, $stateParams ,settings, categoryService, blockUI) {

    });

Comments

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.