Я хочу отобразить текст «Подписан», если пользователь подписан, и «Подписаться», если он не подписан.Для этого я вызываю из серверной части сервис, который предоставляет мне объект, если он подписан, и выдает ошибку, не найденную, если он не подписан.Теперь, как я могу изменить отображаемый текст независимо от того, подписан он или нет.
Я работаю над Angular 7.
import { Component, OnInit } from '@angular/core';
import { CategoryService } from '@ikubinfo/core/services/category.service';
import { Router } from '@angular/router';
@Component({
selector: 'ikubinfo-dashboard',
templateUrl: './dashboard.component.html',
styleUrls: ['./dashboard.component.css']
})
export class DashboardComponent implements OnInit {
categories: Object;
text: string;
constructor(private categoryService: CategoryService, private router: Router) {
this.categories=[];
this.text='';
}
ngOnInit() {
this.categoryService.getAllCategories().subscribe(res=>{
this.categories=res;
console.log(this.categories);
});
}
subscribe(id: number){
this.categoryService.subscribe(id).subscribe(res=>{
});
}
isSubscribed(id:number){
return this.categoryService.isSubscribed(id).subscribe(res=>{
this.text='Subscribed';
},err=>{
this.text='Subscribe';
});
}
}
И HTML
<div class="row">
<div class="col col-xl-6 col-lg-12" *ngFor="let category of categories">
<ikubinfo-panel header="Category">
<div panel-content ng-onload="isSubscribed(category.categoryId)">
<h1>{{ category.categoryName }}</h1>
<p>{{ category.categoryDescription }}</p>
<button class="btn btn-success" (click)="subscribe(category.categoryId)">{{ text }}</button>
</div>
</ikubinfo-panel>
</div>
</div>