Below is my Quote class I have set the up-vote and down-vote properties to initial value of 0
export class Quote {
showDescription: boolean;
upvotes: number;
downvotes: number;
constructor(
public content:string,
public publisher:string,
public author:string,
public datePublished:Date
) {
this.showDescription = false;
this.upvotes = 0;
this.downvotes = 0;
}
}
Below is my HTML button
<li *ngFor = 'let quote of quotes; let i = index' quotes>
<div class="col-md-6 downvotes">
................
<img src="assets/down-arrow.png" alt="" (click)="downVote(i)">
<span >{{quote.downvotes}}</span>
...................
</div>
</li>
This how I'm calling the downvote function when button is clicked
import { Component, OnInit } from '@angular/core';
import { Quote } from '../quote'
@Component({
selector: 'app-quote',
templateUrl: './quote.component.html',
styleUrls: ['./quote.component.css']
})
export class QuoteComponent implements OnInit {
............
downVote(index:number) {
this.quotes[index].downvotes -= 1;
.................
}
question from:
https://stackoverflow.com/questions/66065323/i-have-a-button-that-down-votes-a-initial-set-number-by-1-when-clicked-but-i-wan 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…