Javascript state.go angularjs中参数的默认值

Javascript state.go angularjs中参数的默认值,javascript,angularjs,Javascript,Angularjs,我在我的app.js中创建了路由,我需要在upsrURL中接收两个参数 .state('upsr', { url: '/upsr/:QuestionIdIndex/:LangId', templateUrl: 'modules/study/question/question-details.html', controller: 'upsrCtrl' }) 如何使用$state.go而不发送以下任何参数 $state.go('upsr'); 而不是: $state.go('u

我在我的
app.js
中创建了路由,我需要在
upsr
URL中接收两个参数

.state('upsr', {
   url: '/upsr/:QuestionIdIndex/:LangId',
   templateUrl: 'modules/study/question/question-details.html',
   controller: 'upsrCtrl'
})
如何使用
$state.go
而不发送以下任何参数

$state.go('upsr');
而不是:

$state.go('upsr',{
    QuestionIdIndex : 0,
    LangId:0
});
注意:如果没有任何参数,则将其设置为默认值。比如说

QuestionIdIndex = 0; 
LangId = 0;
我的问题是如果我只使用
$state.go('upsr')那么它将是错误的

有什么办法解决这个问题吗?

你需要把它们变成

你需要把它们做成


您可以在定义状态时使用
params
选项来实现这一点

注意:可选参数需要,因此它将与
$urlRouterProvider匹配。否则('/upsr')


您可以在定义状态时使用
params
选项来实现这一点

注意:可选参数需要,因此它将与
$urlRouterProvider匹配。否则('/upsr')



$state.go('upsr',{'questiondIndex':'0','LangId':0'});我知道..我只想使用
$state.go('upsr')
作为默认值,而不是“$state.go('upsr',{'questiondIndex':'0','LangId':0')`$state.go('upsr',{'questionId':'0','LangId':0'});我知道..我只想使用
$state.go('upsr')
作为默认值,而不是“$state.go('upsr',{'questiondIndex':'0','LangId':0')`也可以在
$urlRouterProvider中实现。否则('/upsr')
?@Imran可能,您使用的是哪个版本?如何检查?您可以在
angular ui router.js的标题上看到。
@Imran新版本的ui router实现可选参数,我已经更新了我的答案也可以在
$urlRouterProvider中实现。否则('/upsr')
?@Imran可能,您使用的是哪个版本?如何检查?您可以在
angular ui router.js的标题上看到。
@Imran较新版本的ui router实现可选参数,我已经更新了我的答案,也可以在
$urlRouterProvider中实现。否则('/upsr'))
?@Imran yes您可以设置
QuestiondIndex
LangId
?的默认值,也可以在
$urlRouterProvider中实现。否则('/upsr')
?@Imran yes您可以设置
QuestiondIndex
LangId
的默认值?
state('upsr', {
   url: '/upsr/:QuestionIdIndex?/:LangId?',
   templateUrl: 'modules/study/question/question-details.html',
   controller: 'upsrCtrl'
})
.state('upsr', {
   url: '/upsr/{QuestionIdIndex}/{LangId}',
   params: {
      QuestionIdIndex: { value: 0 },
      LangId: { value: 0 }
   },
   templateUrl: 'modules/study/question/question-details.html',
   controller: 'upsrCtrl'
})