ionic 1.X ui参数

AngularJS. UI Router. Optional and Default Params in Route
Let's take a look at example, when we need to show list of items by categories with pagination.
Angular State Route Parameters
All Route parameters are optional by default. That's why you should use trailing slashes in case they are empty. For example, route /items/1 and /items/ will work, but not this one: /items. Let's take a closer look and pass category and page through route params:
state('items-list', {
url: '/items-list/:cat/:page',
templateUrl: 'items-list.html',
controller: function($scope, $stateParams) {
$scope.category = $stateParams.cat;
$scope.page = $stateParams.page;
},
// default uri params
params: {
cat: 'all' ,
page: 1
}
});

Then, you're ready to go with links like this:
<a ui-sref="items-list({ cat: 'category-name' })">Category Name</a>

This link will navigate to /items-list/category-name/1.
Angular State Query Parameters
All query parameters are mapped to $stateParams object of UI Router. Let's pass category and page through a query parameters.
state('items-list', {
url: '/items-list?cat&page',
templateUrl: 'items-list.html',
controller: function($scope, $stateParams) {
$scope.category = $stateParams.cat || 'all';
$scope.page = $stateParams.page || 1;
}
});

After that, you may use such links:
<a ui-sref="items-list({ cat: 'category-name' })">Category Name</a>

Such link will navigate to /items-list?cat=category-name.
Angular Non-URL State Parameters
It is possible to pass parameters to state without showing them in the route.
state('items-list', {
url: '/items-list',
templateUrl: 'items-list.html',
controller: function($scope, $stateParams) {
$scope.category = $stateParams.cat;
},
params: {
cat: 'all' //default category
}
});

Now if you create such link:
<a ui-sref="items-list({ cat: 'category-name' })">Category Name</a>

It will navigate to /items-list. But category will be available in $stateParams.
In this case, it's not possible to share a link, but it works :-).
If you wan't to share a link with hidden parameters, you may create a button for generating link with full parameters and create a special state that will parse that link and redirect to current state with hidden parameters. Briefly that's it :-)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值