I have a nb-card, I want to be able to minimize and maximize it. I have written the following code. I can not get the card to be minimized.
nb-card status="primary" [ngClass]="{'collapsed': isCollapsed}">
<nb-card-header>
<div class="row justify-content-between align-items-center">
<div class="col-auto">Client Systems Associated Assessment</div>
<div class="col-auto">
<button nbButton ghost (click)="toggleCollapse()">
<nb-icon [icon]="isCollapsed ? 'plus-outline' : 'minus-outline'"></nb-icon>
</button>
<button nbButton ghost (click)="closeDialog()">
<nb-icon icon="close-outline"></nb-icon>
</button>
</div>
</div>
</nb-card-header>
And here is the typescript code:
import { NbCardComponent } from '@nebular/theme';
@ViewChild(NbCardComponent) card: NbCardComponent;
isCollapsed = false;
toggleCollapse() {
console.log("Testing the minimize button");
this.isCollapsed = !this.isCollapsed;
}
I can reach the toggleCollapse() function because I can see the output in the Console log. Just that the card does not get minimized.
May you please point me to the right direction?
3
Answers
Looking at the documentation, it doesn’t look like
nb-card
can be collapsedhttps://akveo.github.io/nebular/docs/components/card/overview#nbcardcomponent
But I can see that there is a component called
Accordion
that is probably doing what you want:https://akveo.github.io/nebular/docs/components/accordion/overview#nbaccordioncomponent
To minimize and maximize a nb-card in Angular, you can use the nb-card’s collapsed input property to control the state of the card. Here’s how you can modify your code to achieve this:
In your HTML template, replace the isCollapsed property with collapsed:
In your component, modify the toggleCollapse() function to toggle the value of isCollapsed:
With these changes, clicking the button with the plus/minus icon should now toggle the nb-card between its minimized and maximized states.
Note that you can also use CSS to customize the appearance of the nb-card when it is in its collapsed state. In your example, the ngClass directive is used to add the collapsed class to the card’s wrapper element when it is collapsed. You can use this class to apply custom styling to the card when it is minimized.