Imran Imran - 1 year ago 84
AngularJS Question

Default value for parameters in state.go angularjs

I have make route in my

, well I need receive two parameters in

.state('upsr', {
url: '/upsr/:QuestionIdIndex/:LangId',
templateUrl: 'modules/study/question/question-details.html',
controller: 'upsrCtrl'

How I can use
without sending any parameters like below?


Instead of:

QuestionIdIndex : 0,

Note: If there were no any parameters, then it will set as default value. For example

QuestionIdIndex = 0;
LangId = 0;

My problems was if I just use
then it would be error.

Any ideas how to solve this?

Answer Source

You can achieve this by using the params option when defining your state.

Note: optional parameters requires angular-ui-router@1.0.0-beta.3 so then it will match with $urlRouterProvider.otherwise('/upsr');

.state('upsr', {
   url: '/upsr/{QuestionIdIndex}/{LangId}',
   params: {
      QuestionIdIndex: { value: 0 },
      LangId: { value: 0 }
   templateUrl: 'modules/study/question/question-details.html',
   controller: 'upsrCtrl'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download