Мне нужно показать внутри ngFor значений, чем в другой переменной, я не знаю, возможно ли это,
теперь у меня есть это
Компонент
import { Component, OnInit, OnDestroy } from '@angular/core';
import { ListarAfiliacaoService } from '../services/listar.afiliacao.service';
import { MatDialog } from '@angular/material/dialog';
import { ListarImovelService } from '../services/listar.imovel.service';
import { Observable } from 'rxjs';
@Component({
selector: 'app-afiliacao',
templateUrl: './afiliacao.component.html',
styleUrls: ['./afiliacao.component.css']
})
export class AfiliacaoComponent implements OnInit, OnDestroy {
constructor(private listAffiliationService: ListarAfiliacaoService, public dialog: MatDialog) { }
affiliation$: Observable<any>;
affiliationPending$: Observable<any>;
afiliationDenied: any;
accessCount: any;
ngOnInit(): void {
this.affiliation$ = this.listAffiliationService.listAffiliation();
this.affiliationPending$ = this.listAffiliationService.listAffiliationPending();
this.listAffiliationDenied();
}
countAccess(refValue) {
this.listAffiliationService.countAccess(refValue).subscribe(data => {
this.accessCount = data.length;
}, err => {
console.log(err)
})
}
listAffiliationDenied() {
this.listAffiliationService.listAffiliationDenied().subscribe(data => {
this.afiliationDenied = data;
}, err => {
console.log(err)
})
}
ngOnDestroy(): void {
}
}
Сервис
import { Injectable } from '@angular/core';
import { HttpClient , HttpHeaders, HttpResponse } from '@angular/common/http';
import { AuthService } from './auth.service';
import { Observable } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class ListarAfiliacaoService {
constructor(private http: HttpClient, private authService: AuthService) { }
listAffiliation(): Observable<any> {
this.authService.loadToken();
let reqheaders = new HttpHeaders({
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + this.authService.authToken
});
return this.http.get('http://192.168.15.64:4000/afiliacao/'+this.authService.user_id, {headers: reqheaders})
}
listAffiliationPending(): Observable<any> {
this.authService.loadToken();
let reqheaders = new HttpHeaders({
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + this.authService.authToken
});
return this.http.get('http://192.168.15.64:4000/afiliacao/pedido/'+this.authService.user_id, {headers: reqheaders})
}
listAffiliationDenied(): Observable<any> {
this.authService.loadToken();
let reqheaders = new HttpHeaders({
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + this.authService.authToken
});
return this.http.get('http://192.168.15.64:4000/afiliacao/negado/'+this.authService.user_id, {headers: reqheaders})
}
countAccess(ref): Observable<any> {
this.authService.loadToken();
let reqheaders = new HttpHeaders({
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + this.authService.authToken
});
return this.http.get('http://localhost:4000/count/'+ref, {headers: reqheaders})
}
}
HTML
<table class="table table-hover">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Total access count</th>
<th scope="col">Movel ID</th>
<th scope="col">Status</th>
<th></th>
</tr>
</thead>
<tbody>
<tr class="table-success" *ngFor="let afilia of affiliation$ | async">
<th scope="row">{{afilia.ref}}</th>
<td>{{}}</td>
<td>{{afilia.imovel_Id}}</td>
<td>{{afilia.status}}</td>
<td><mat-icon aria-hidden="false" aria-label="Example home icon">info</mat-icon></td>
</tr>
</tbody>
</table>
Я не знаю, что я поставил, чтобы сделать это «Общее количество доступа», я создал функции, но не могу это показать. Это refValue - afilia.ref внутри HTML.
Я поместил весь служебный код и компонент