数据库中的Angular 5通配符路由

时间:2018-01-19 09:08:52

标签: angular routing angular2-routing url-routing angular5

我有一个数据库类别列表,如下所示:



[
  "Travel",
  "Apparel & Clothing",
  "Footwear",
  "Kids & Children",
  "Grocery",
  "Food & Beverage",
  "Innerwear & Swimwear",
  "Hotels",
  "Bus Tickets",
  "Mobiles & Tablets",
  "Personalized Gifts",
  "Jewellery & Coins",
  "Car & Taxi Rental",
  "Pharmacy",
  "Watches",
  "Bags & Wallets",
  "Gifts & Flowers",
  "Accessories",
  "Games",
  "Health",
  "Beauty & Personal Care",
  "Electronics"
]




我正在尝试从此类别列表创建路由,我不知道如何处理列表中某些类别的路由。

例如:

Apparel & Clothing
Bus Tickets

我如何处理'&'符号和角度为5的路由系统中的空间

1 个答案:

答案 0 :(得分:0)

我找到了类似于帮助器的解决方案,我们在Angular 5中有Pipes概念。

它帮助了我:

https://feedback.azure.com/forums/217298-storage/suggestions/4134167-infinite-ttl-for-queue-messages?category_id=69698

https://github.com/angular/angular-cli

我的自定义管道删除空格和特殊字符:



import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
  name: 'removeSpaceCharacters'
})
export class RemoveSpaceCharactersPipe implements PipeTransform {
  transform(value: string): string {
    let newValue = value.replace(/[^A-Z0-9]/ig, "");
    return `${newValue}`;
  }
}