Angular +Ionic实现关注与取消关注

Angular +Ionic实现关注与取消关注

1.html中:

<div class="middle-rate-shop-name" *ngIf="isShowContent">
      <div class="middle-rate-shop-name-img" >
        <img [src]="shopInfoList.storeLogo">
      </div>
      <div class="middle-rate-shop-name-text">
        <div class="rate-shop-name-text-qzh">
         {{shopInfoList.shortName}}
        </div>
        <span><img src="../../../assets/icon/search-icon/golden.png" alt="">{{shopInfoList.memberLevel}}</span>
      </div>
      <div class="middle-rate-shop-name-concern">
       <div class="concern" *ngIf="!concernIs" (click)="concernIsNo()">
        <img src="../../../assets/icon/search-icon/concern.png" alt="">
        关注
       </div>
       <div class="unconcern" *ngIf="concernIs"  (click)="concernIsNo()">
        已关注
       </div>
     </div>
 </div>
</div>

2.ts

 public concernIs:boolean;//是否关注
 public newOnLine = {
    storeId:'',
  };
  
  constructor(
    private rest: RestService,
    //引入路由
    private router: Router,
    private activatedRoute: ActivatedRoute,
    private navCtrl: NavController,
   
    private loadingCtrl: LoadingController,
    public appService: AppService,
    public localStorageService: StorageService,
    private toastCtrl: ToastController
  )
  {  
     super(appService, localStorageService);
    this.goodsId = this.activatedRoute.snapshot.paramMap.get('goodsId');
    this.storeId = this.activatedRoute.snapshot.paramMap.get('storeId');
  }

  //6,关注店铺
  async  getStoreinsert() {
    const goodsReq = {
      'storeId':this.newOnLine.storeId,
    }
    this.rest.apiPost(goodsReq, this.rest.getStoreinsert).subscribe(res => {
      const { status, msg, data } = res;
      if (status == 200) {
        this.concernIs=true;
        console.log("关注店铺",data);
        alert("关注成功")
      } else {
        console.log("请求失败");
      }
    });
  }
  //7,取消关注
  async getdeletByStoreId() {
    const goodsReq = {
      ids:this.newOnLine.storeId,	//店铺的ID
    }
    await this.rest.apiPost(goodsReq, this.rest.getdeletByStoreId).subscribe(res => {
      const { status, msg, data } = res;
      if (status == 200) {
        console.log("======取消关注=======");
        alert("取消成功")
      } else {
        console.log("请求失败");
      }
    });
  } 



  //8,6<-->7取消与关注店铺
  concernIsNo(){
    this.concernIs=!this.concernIs
    //关注
    if(this.concernIs){
      this.getStoreinsert();
    //取消关注
    }if(!this.concernIs){

     this.getdeletByStoreId();
    }
  }

3.效果

在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Angular是一个流行的JavaScript框架,用于构建Web应用程序。Ionic是基于Angular的开源移动应用开发框架,它提供了一套UI组件和具,帮助开发者构建跨平台的移动应用程序。 Swiper是一个流行的移动端滑动组件库,它提供了丰富的滑动效果和交互功能,可以用于创建漂亮的轮播图、图片浏览器等。 结合AngularIonic,你可以轻松地集成Swiper组件到你的移动应用中。首先,你需要在你的Angular项目中安装Swiper组件库。可以使用npm命令来安装: ``` npm install swiper --save``` 安装完成后,你可以在你的Ionic组件中引入Swiper组件,并在模板中使用它。以下是一个简单的示例: ```typescriptimport { Component } from '@angular/core'; import SwiperCore, { Navigation, Pagination } from 'swiper/core'; SwiperCore.use([Navigation, Pagination]); @Component({ selector: 'app-swiper', template: ` <swiper [navigation]="true" [pagination]="true"> <ng-template swiperSlide>Slide1</ng-template> <ng-template swiperSlide>Slide2</ng-template> <ng-template swiperSlide>Slide3</ng-template> </swiper> `, }) export class SwiperComponent {} ``` 在上面的示例中,我们首先引入了Swiper组件库,并注册了所需的Swiper模块(例如Navigation和Pagination)。然后,在组件的模板中,我们使用`<swiper>`标签创建了一个Swiper实例,并在内部添加了三个滑动的内容块。 你可以根据你的需求自定义Swiper的配置和样式。更多关于Swiper的用法和配置,你可以参考Swiper官方文档。 希望这可以帮助到你!如果你还有其他问题,请继续提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值