当单击“收藏夹”按钮时,它将获得收藏夹,而当我取消收藏夹时,它将变得收藏夹。但是问题是,如果该产品是我的最爱,然后注销并登录。然后它不会显示为喜欢的颜色,但功能正常。只有颜色不能正常工作。对于每个人都在说,isFavorite的值不会在应用程序的整个生命周期中持续存在。一旦销毁了此组件,isFavorite也将销毁。请就这些帮助我
`Favorite.component.html`
`<button class="favouri" (click)="isFavoritee(x.ad_Id)"><i class="fa"
[ngClass]="{'fa-heart' : isFavorite[x.ad_Id], 'fa-heart-o': !isFavorite[x.ad_Id] }"></i></button>`
`Favorite.component.ts`
`isFavorite: boolean[] = [];`
`isFavoritee(elem: any) {
// this.toggle = !this.toggle;
this.isFavorite[elem] = !this.isFavorite[elem];
this.favouritedata = [];
const favo = {
'login_Id': this.localservice.getLoginId() ? this.localservice.getLoginId() : '',
'ad_id' : elem ? elem : '',
'category_Id' : 27,
'mode': 'INSERT'
};
this.authservice.post('/api/Favourite/insert', favo).subscribe(data1 => {
this.favouritedata = data1;
console.log(this.favouritedata);
}, error => {
alert('something went wrong');
});
}`