Angular+Ionic路由传值实现分类搜索

Angular+Ionic路由传值实现分类搜索

1,发送页面文件中,路由绑定待传的值

 <li *ngFor="let item of selectedClassList"
                            [routerLink]="['/product-reclassify',item.categoryId ,item.name]"
                            (click)="changeTadId(item)">
                            <div class="commodity-img">
                             <img [src]="item.pictureUrl" >
                           </div>
                           <div class="commodity-text">
                                {{item.name}}
                           </div>
 </li>

2,发送ts文件选中赋值

  changeTadId(item) {
    this.tagIdList = item.categoryId;
    this.tagName = item.name;
    console.log(item.name+this.tagIdList);
  }

3,app-routing.module.ts
路由文件中
接受页接口的path下绑定:

:tagId/:tagName

  { path: 'product-reclassify/:tagId/:tagName', loadChildren: './pages/product-reclassify.....}

4,
接收ts文件中引入
this.tagId = this.activatedRoute.snapshot.paramMap.get(‘tagId’);

constructor(
    private rest: RestService,
    private router: Router,
    private activatedRoute: ActivatedRoute,
    private navCtrl: NavController,
    private menu: MenuController,
    private loadingCtrl: LoadingController,
    public appService: AppService,
    public localStorageService: StorageService,
    private toastCtrl: ToastController
  )
  { 
    super(appService, localStorageService);
    this.tagId = this.activatedRoute.snapshot.paramMap.get('tagId');
    this.tagName = this.activatedRoute.snapshot.paramMap.get('tagName');
  }

5,接收文件中使用
ts中

//产品搜索
  async getProductSearch() {
    const userInfo = {
      'pageNo': 1,
      'pageSize': 16,
      'price': 1 - 100,
      'categoryId': this.tagId,//传入接收的tagId
    }
    this.rest.apiPost(userInfo, this.rest.getProductSearch).subscribe(res => {
      const { status, msg, data } = res;
      if (status == 200) {
        console.log("------产品分类搜索-----");
        this.tagSearchList = res.data.result;
        console.log(this.tagSearchList);
      } else {
        console.log("请求失败");
      }
    });
  }

html中

 <div class="selected-tag" *ngIf="selectTag" (click)="touchTag()">
                 {{this.tagName}}//展示接收的agName
                 <div class="sure-tag" *ngIf="selectTag">
                   <ion-icon name="close-outline" class="sure-outline"></ion-icon>
                 </div>
  </div>

6.初步效果
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值