Angular 基于单击的thumb更改完整图像无效,方法正在使用中
我已经在Angular中创建了一个gallery应用程序,它显示3个拇指和一个大图像。根据点击的拇指,完整图像应该-,但不会更改-数据和方法在服务级别上一级。Angular 基于单击的thumb更改完整图像无效,方法正在使用中,angular,angular7,Angular,Angular7,我已经在Angular中创建了一个gallery应用程序,它显示3个拇指和一个大图像。根据点击的拇指,完整图像应该-,但不会更改-数据和方法在服务级别上一级。 当i console.log fullImage on images.component.ts时,您的多媒体资料服务中需要例如ReplaySubject: subject = new ReplaySubject<string>(1); onDislayImage = (i: number) => { this.disp
当i console.log fullImage on images.component.ts时,您的多媒体资料服务中需要例如ReplaySubject:
subject = new ReplaySubject<string>(1);
onDislayImage = (i: number) => {
this.displayedImage = this.imagesDomain + this.imagesNumber[i];
this.subject.next(this.displayedImage);
}
yourSubject(): ReplaySubject<any> {
return this.subject;
}
别忘了取消对destroy的订阅。谢谢。经过一些阅读和学习,我决定从以下内容开始:``activeImage=newsubject();this.activeImage.next(this.displayedImage=this.imagesDomain+this.imagesNumber[i])```
import { Component, OnInit, OnDestroy } from '@angular/core';
import { GalleryService } from '../gallery.service';
@Component({
selector: 'app-images',
templateUrl: './images.component.html',
styleUrls: ['./images.component.scss']
})
export class ImagesComponent implements OnInit, OnDestroy {
fullImage: string;
constructor(private imagesService: GalleryService) { }
ngOnInit() {
this.fullImage = this.imagesService.displayedImage;
}
ngOnDestroy(): void {}
}
subject = new ReplaySubject<string>(1);
onDislayImage = (i: number) => {
this.displayedImage = this.imagesDomain + this.imagesNumber[i];
this.subject.next(this.displayedImage);
}
yourSubject(): ReplaySubject<any> {
return this.subject;
}
this.fullImage = this.imagesService.displayedImage;
this.imagesService.yourSubject().asObservable().subscribe((res) => {
this.fullImage = res;
});