AngularJS – route with parameter to be accesses globally


I am creating a survey form in AngularJS. The requirement is this that the survey link with surveyId in parameter will be provided in email.

I tired the following code, but I can’t access the surveyId in the receiving controller, it shows undefined. Moreover when I try to access the url with parameter directly, it does not load.

This is how I am trying to access the link directly in my local environment, where 4 is the surveyId

Can someone please guide me in the right direction?`

var app = angular.module('mainApp', ['ngRoute']);

app.config(['$routeProvider', '$locationProvider',

  function($routeProvider, $locationProvider) {


      enabled: true,
      requireBase: false
    $routeProvider.when('/fillSurvey/:surveyId', {
        templateUrl: 'surveyManagement/views/surveysList.html',
        controller: 'fillSurveyCtrl'

        redirectTo: '/'


app.controller('fillSurveyCtrl', ['$scope', '$location', '$http', '$localStorage', '$filter', '$interval', function($scope, $location, $http, $localStorage, $filter, $interval, $routeParams) {

  $scope.surveyId = $routeParams.surveyId;



So I was missing to add dependency ‘$routeParams’ that is why got undefined.
Can someone please guide me how to make the link accessible from anywhere like this

where 5 is the survey id



Your controller is not configured properly.

[‘$scope’, ‘$location’, ‘$http’, ‘$localStorage’, ‘$filter’, ‘$interval’,

function($scope, $location, $http, $localStorage, $filter, $interval, $routeParams

I hope you figured it out.

Answered By – Altaf Khokhar

Answer Checked By – Senaida (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.