当从一个状态移动到另一个状态时,我必须传递一些需要加密的ID。 URL中存在的ID应该是加密的,并且当通过$ stateParams在控制器中访问它时,它必须被解密。
var list = ['John', 'Paul', 'George', 'Ringo'];
$urlMatcherFactoryProvider.type('listItem', {
encode: function(item) {
// Represent the list item in the URL using its corresponding index
return list.indexOf(item);
},
decode: function(item) {
// Look up the list item by index
return list[parseInt(item, 10)];
},
is: function(item) {
// Ensure the item is valid by checking to see that it appears
// in the list
return list.indexOf(item) > -1;
}
});
$stateProvider.state('list', {
url: "/list/{item:listItem}",
controller: function($scope, $stateParams) {
console.log($stateParams.item);
}
});
$state.go('list', { item: "Ringo" });
将网址更改为' / list / 3',应记录" Ringo"到控制台