栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

角度ui.router ui-sref替换URL字符-美化

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

角度ui.router ui-sref替换URL字符-美化

注册用于封送和拆组数据的自定义类型。此处的文档:http : //angular-ui.github.io/ui-
router/site/#/api/ui.router.util。$ urlMatcherFactory

让我们定义一个自定义类型。实现编码,解码,是和模式:

  var productType = {    enpre: function(str) { return str && str.replace(/ /g, "-"); },    depre: function(str) { return str && str.replace(/-/g, " "); },    is: angular.isString,    pattern: /[^/]+/  };

现在,将自定义类型注册为“产品”

$urlMatcherFactoryProvider

app.config(function($stateProvider, $urlRouterProvider, $urlMatcherFactoryProvider) {  $urlMatcherFactoryProvider.type('product', productType);}

现在,将您的url参数定义为产品,然后自定义类型将为您完成映射:

  $stateProvider.state('baseproductdetail', {    url: '/detail/{productName:product}-:productId/',    controller: function($scope, $stateParams) {       $scope.product = $stateParams.productName;      $scope.productId = $stateParams.productId;    },    template: "<h3>name: {{product}}</h3><h3>name: {{productId}}</h3>"  });

工作小伙伴:http
://plnkr.co/edit/wsiu7cx5rfZLawzyjHtf?
p=
preview



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/448284.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号