I am very new to angular, I am trying to send a new Rate to the dataBase using rateChange in ngb-rating but it have been fired while it gitting the values from the server for example when I try to console.log the Rate it print the rate that I am getting from the DataBase.
this is the Html Templet:
<div class="card-group d-flex justify-content-center">
<div class="row justify-content-center">
<div *ngFor="let item of items" class="col-sm-4 card bg-light"
style=" max-width: 17rem; border:none; display: flex;margin: 30px;">
<div class="card-img-top" style="height: 45%; white-space: nowrap;">
<span class="helper"></span>
<img src="{{item.image}}" style="margin: 0px; vertical-align: middle; display: inline-block;"
width="100%" alt="item.Name">
</div>
<div class="card-body">
<h5 class="card-title" style="text-align: center;">{{item.Name}}</h5>
<p class="card-description" style="height: 30%;">{{item.Description | Summery}}</p>
<h5 class="card-text price" style=" margin: 0px 0px 20px 0px ;">{{item.price | currency}}
</h5>
<ngb-rating [max]='5' [(rate)]="item.stars" *ngIf="" (rateChange)="onRateChange($event)">
<ng-template let-fill="fill">
<span class="star" [class.filled]="fill === 100">★</span>
</ng-template>
</ngb-rating>
</div>
<button class="btn btn-primary mx-auto">add to cart</button>
</div>
</div>
</div>
ts file:
import { Component, OnInit } from '@angular/core';
import { Item } from 'src/moduls/item';
import { ItemService } from './item.service';
@Component({
selector: 'app-item',
templateUrl: './item.component.html',
styleUrls: ['./item.component.css']
})
export class ItemComponent implements OnInit {
constructor(private itemService: ItemService) { }
items: any[] = [];
onRateChange(newRate: number) {
console.log(newRate);
}
ngOnInit(): void {
this.getItems();
}
getItems() {
return this.itemService.getaData().subscribe(
Response => {
this.items = Response as Item[];
console.log(this.items);
}
)
}
}