alyn000r
alyn000r

Reputation: 566

AngularJS $routeParams is undefined

I am a newbie to AngularJS and I am trying to use $routeParams in my code, searching the previous answers here I have made sure that I have added '$routeParams' as part of my array injection and the function both and I am not using ui-router module. However I am still getting an undefined when I try to log it.

My Angular App is as follows:

var RAFITOAPP = RAFITOAPP || {}

RAFITOAPP.app = angular.module('app', [
  'ngRoute'
]).config(['$routeProvider', function($routeProvider) {
  $routeProvider.
    when("/line/:userAccountId", {templateUrl: "assets/partials/line.html", controller: "LineController"}).
    when("/floormap", {templateUrl: "assets/partials/floormap.html", controller: "MapController"}).
    when("/report", {templateUrl: "assets/partials/reports.html", controller: "ReportController"}).
    when("/addNew", {templateUrl: "assets/partials/add_new.html", controller: "addNewController"}).
    when("/profile", {templateUrl: "assets/partials/account.html", controller: "accountSettingsController"}).
    otherwise({redirectTo: '/line'});
}]);

My Controller is as follows:

RAFITOAPP.app.

controller('LineController', ['$scope','$rootScope','$routeParams', function($rootScope, $scope, $location, $routeParams) {
    $scope.$on('$viewContentLoaded', function() {
        console.log($routeParams);
        change('line');
        if(control != 1){
            setTimeout(function() {
                script1fire();
            } , 100);
            control = 1;
        }
    })
}]);

Please advise on what am I missing ? Any help will be appreciated greatly. If you wish to see the HTML Page causing the issue it is

Upvotes: 0

Views: 4049

Answers (1)

jad-panda
jad-panda

Reputation: 2547

Your array dependencies and functions arguments are not same. it should be something like this '['$rootScope', '$scope', '$location', '$routeParams', function($rootScope, $scope, $location, $routeParams)' instead of '['$scope','$rootScope','$routeParams', function($rootScope, $scope, $location, $routeParams)'

RAFITOAPP.app
  .controller('LineController', ['$rootScope', '$scope', '$location', '$routeParams',
    function($rootScope, $scope, $location, $routeParams) {
      $scope.$on('$viewContentLoaded', function() {
        console.log($routeParams);
        change('line');
        if (control != 1) {
          setTimeout(function() {
            script1fire();
          }, 100);
          control = 1;
        }
      })
    }
  ]);

Upvotes: 6

Related Questions