Ich habe diese zwei Divs, die basierend auf Daten zeigen/verbergen; In diesem Fall, wenn eine bestimmte Firma eine Abrechnungskarte hat, wird sie die Info der Karte anzeigen, sonst wird sie das Div anzeigen, wo Sie diese Informationen hinzufügen können. Aber nur ein Div zeigt und ich weiß nicht warum. Der Code:Angular: versteckte div basierend auf Daten nicht angezeigt
TS
public comapanyHasBilling(companyId: string) {
const searchID = this.billingList.find(item => item.companyId === item.companyId)
if (searchID !== undefined){
console.log(searchID.companyId)
}
});
}
HTML (erste div)
<!--If there is a card-->
<div *ngIf="!comapanyHasBilling(entity.id)" class="icon-company-title">
<div class="business-icon">
<i class="material-icons md-18">credit_card</i>
</div>
<span class="company-card-title">Credit Card</span>
<button class="" mat-icon-button [matMenuTriggerFor]="menu">
<i class="material-icons edit">mode_edit</i>
</button>
</div>
<!-- Content credit card -->
<mdl-card-title mdl-card-expand fxLayout="column" fxLayoutAlign="start start" fxLayoutGap="3px">
<span class="company-card-content company-card-content-edges">cardRef</span>
<span class="company-card-content">card</span>
<span class="company-card-content">test</span>
<span class="company-card-content company-card-content-edges" fxLayoutGap="5px">Name</span>
</mdl-card-title>
Und das andere div
<!--If there is no card-->
<mdl-card-title *ngIf="!comapanyHasBilling(entity.id)" mdl-card-expand fxLayout="column" fxLayoutAlign="center center" fxLayoutGap="30px">
<span class="company-card-title">Payment Method</span>
<button (click)="createBillingCard(entity.id)" mat-raised-button class="add-button">ADD</button>
</mdl-card-title>
</mdl-card>
: Egal, was, wenn ich dieses Typs * ngIf =“ ! comapanyHasBilling (entity.id) auf jedem Div, sie wird erscheinen ... Warum? Die Logs sagen, dass ich die ID
bekommeEDIT:
TS:
public companyHasBilling(companyId: string) {
const searchID = this.billingList.find(item => item.companyId === companyId)
if (searchID !== undefined) {
console.log(searchID.companyId);
}
return searchID;
};
HTML
<mdl-card-title *ngIf="companyHasBilling(entity.id) === null" mdl-card-expand fxLayout="column" fxLayoutAlign="center center" fxLayoutGap="30px">
<span class="company-card-title">Payment Method</span>
<button (click)="createBillingCard(entity.id)" mat-raised-button class="add-button">ADD</button>
</mdl-card-title>
<div *ngIf="companyHasBilling(entity.id) !== null" class="icon-company-title">
<div class="business-icon">
<i class="material-icons md-18">credit_card</i>
</div>
<span class="company-card-title">Credit Card</span>
<button class="" mat-icon-button [matMenuTriggerFor]="menu">
<i class="material-icons edit">mode_edit</i>
</button>
</div>
aber noch nichts ....
Sollte nicht die erste Bedingung be '* ngIf =" comapanyHasBilling (entity.id) "' (ohne das '!')? Auch: 'comapanyHasBilling' sollte' true' oder 'false' zurückgeben. – ConnorsFan
es macht keinen Unterschied, es schaltet nur – Mellville