onChange角???我该如何从功能更新价值

时间:2019-07-24 04:24:00

标签: angular typescript

如何将值pos从nextPrize()更新为this.pos = this.prizes.findIndex(x => x.name === typePrize);

通常是单击放大然后显示图像时的放大,我们有两个按钮分别具有“位置值”(0,1,2,3,4,5)和图像捕捉位置(0,1,2,3 ,4,5)(取决于您单击放大的时间)。 当我单击下一步按钮或上一个按钮时,它不会将pos值更新为图像,因此我仍然会得到旧图片而不是新图片! 如何更新pos值?

 import { Component, Output, EventEmitter, Inject, AfterViewInit, OnInit } from '@angular/core';
import {Location} from '@angular/common';
import { PrizesService } from 'app/core/service/prizes/prizes.service';
import { CommonService } from 'app/core/service/api/common.service';
import { LotteryService } from 'app/core/service/lottery/lottery.service';


@Component({
  selector: 'app-lottery-product-detail',
  templateUrl: './product-detail.component.html',
})
export class ProductDetailComponent implements OnInit, AfterViewInit {
  pos: number;
  prizes: any;

  constructor(
    private location: Location,
    private prizesSv: PrizesService,
    private commonSv: CommonService,
    private lotterySv: LotteryService
  ) {
  }

  ngOnInit() {
    this.lotterySv.convertPrizes$.subscribe(convertItem => {
      this.prizes = convertItem;
    });
    this.prizesSv.prizesPos$.subscribe(typePrize => {
      if (this.prizes) {
        this.pos = this.prizes.findIndex(x => x.name === typePrize);
      }
    });
  }

  ngAfterViewInit() {
    this.commonSv.animate('animate-fadeIn');
  }

  prevPrize() {
    if (this.pos === 0) {
      this.pos = this.prizes.length - 1;
    } else {
      --this.pos;
    }
  }

  nextPrize() {
    if (this.pos === this.prizes.length - 1) {
      this.pos = 0;
    } else {
      ++this.pos;
    }
  }

  closeDialog() {
    this.location.back();
  }

}

0 个答案:

没有答案