This repository has been archived on 2026-05-01. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
PolyNotFound/src/app/user/utils/components/advert/advert.component.ts

40 lines
930 B
TypeScript

import {Component, Input, OnChanges, SimpleChanges} from '@angular/core';
@Component({
selector: 'app-advert',
templateUrl: './advert.component.html',
styleUrls: ['./advert.component.scss']
})
export class AdvertComponent implements OnChanges
{
@Input() ad: any;
@Input() from: string = "search";
image: any;
imageExist: boolean = false;
constructor() { }
ngOnChanges(changes: SimpleChanges): void
{
if((this.ad !== null) && (this.ad !== undefined))
{
const nbImages = this.ad.images.length;
const indexImage = Math.floor(Math.random() * nbImages);
this.image = this.ad.images[indexImage];
this.imageExist = true;
}
}
onClick(): void
{
if((this.ad.url !== "") && (this.ad.url !== null) && (this.ad.url !== undefined)) {
document.location.href = this.ad.url;
}
}
}