Back to Abp

Card Component

docs/en/framework/ui/angular/card-component.md

10.3.06.7 KB
Original Source
json
//[doc-seo]
{
    "Description": "Learn how to use the ABP Card Component with Bootstrap, featuring customizable CardHeader, CardBody, and CardFooter components."
}

Card Component

The ABP Card Component is a wrapper component for the Bootstrap card class. It supports all the features that Bootstrap card component provides.

ABP Card Component has three main components, CardHeader, CardBody and CardFooter. These components have their own class and style inputs

ComponentSelectorInput Properties
CardHeaderabp-card-headercardHeaderClass,cardHeaderStyle
CardBodyabp-card-bodycardBodyClass,cardBodyStyle
CardFooterabp-card-footercardFooterClass,cardFooterStyle

In addition to these components, the Card component provides directives like CardHeader,CardTitle,CardSubtitle,CardImgTop.

DirectiveSelector
CardHeaderabp-card-header,[abp-card-header],[abpCardHeader]
CardTitleabp-card-title,[abp-card-title],[abpCardTitle]
CardSubtitleabp-card-subtitle,[abp-card-subtitle],[abpCardSubtitle]
CardImgTopabp-card-img-top,[abp-card-img-top],[abpCardImgTop]

Usage

ABP Card Component is a part of the theme-shared package. Once you import the necessary components, you can use them. See the examples below:

CardBody

ts
// card-demo.component.ts

import { Component } from '@angular/core';
import { CardComponent, CardBodyComponent } from '@abp/ng.theme.shared';

@Component({
  selector: 'app-card-demo',
  imports: [CardComponent, CardBodyComponent],
  template: ` 
    <abp-card [cardStyle]="{width: '18rem'}">
      <abp-card-body>This is some text within a card body</abp-card-body>
    </abp-card> 
  `,
})
export class CardDemoComponent {}

See the card body result below:

ts

//card-demo.component.ts
import { Component } from '@angular/core';
import { 
  CardComponent,
  CardBodyComponent,
  CardTitleDirective,
  CardSubtitleDirective
} from '@abp/ng.theme.shared';

@Component({
  selector: 'app-card-demo',
  imports: [
    CardComponent,
    CardBodyComponent,
    CardTitleDirective,
    CardSubtitleDirective
  ],
  template: ` 
    <abp-card [cardStyle]="{width: '18rem'}">
      <abp-card-body>
        <h5 abpCardTitle>Card Title</h5>
        <h6 abpCardSubtitle class="mb-2 text-muted">Card subtitle</h6>
        <p class="card-text">
          Some quick example text to build on the card title and make up the bulk of the card's content.
        </p>
        <a href="#" class="card-link">Card link</a>
        <a href="#" class="card-link">Another link</a>
      </abp-card-body>
    </abp-card> 
  `,
})
export class CardDemoComponent {}

See the card title, text and link result below:

Images

ts

//card-demo.component.ts
import { Component } from '@angular/core';
import { CardComponent, CardBodyComponent, CardImgTopDirective } from '@abp/ng.theme.shared';

@Component({
  selector: 'app-card-demo',
  imports: [CardComponent, CardBodyComponent, CardImgTopDirective],
  template: ` 
    <abp-card [cardStyle]="{width:'18rem'}">
      
      <abp-card-body>
        <p class="card-text">
          Some quick example text to build on the card title and make up the bulk of the card's content.
        </p>
      </abp-card-body>
    </abp-card>
  `,
})
export class CardDemoComponent {}

See the card image result below:

List Groups

ts

//card-demo.component.ts
import { Component } from '@angular/core';
import { CardComponent } from '@abp/ng.theme.shared';

@Component({
  selector: 'app-card-demo',
  imports: [CardComponent],
  template: ` 
    <abp-card [cardStyle]="{width:'18rem'}">
      <ul class="list-group list-group-flush">
        <li class="list-group-item">An item</li>
        <li class="list-group-item">A second item</li>
        <li class="list-group-item">A third item</li>
      </ul>
    </abp-card>
  `,
})
export class CardDemoComponent {}

See the group list result below:

Kitchen Sink

ts

//card-demo.component.ts
import { Component } from '@angular/core';
import { 
  CardComponent,
  CardBodyComponent,
  CardImgTopDirective,
  CardTitleDirective
} from '@abp/ng.theme.shared';

@Component({
  selector: 'app-card-demo',
  imports: [
    CardComponent,
    CardBodyComponent,
    CardImgTopDirective,
    CardTitleDirective
  ],
  template: ` 
    <abp-card [cardStyle]="{width:'18rem'}">
      
      <abp-card-body>
        <h5 abpCardTitle>Card title</h5>
        <p class="card-text">
          Some quick example text to build on the card title and make up the bulk of the card's content.
        </p>
      </abp-card-body>
      <ul class="list-group list-group-flush">
        <li class="list-group-item">An item</li>
        <li class="list-group-item">A second item</li>
        <li class="list-group-item">A third item</li>
      </ul>
      <abp-card-body>
        <a href="#" class="card-link">Card link</a>
        <a href="#" class="card-link">Another link</a>
      </abp-card-body>
    </abp-card>
  `,
})
export class CardDemoComponent {}

See kitchen sink result below:

ts

//card-demo.component.ts
import { Component } from '@angular/core';
import { 
  CardComponent,
  CardHeaderComponent,
  CardBodyComponent,
  CardTitleDirective,
  CardFooterComponent
} from '@abp/ng.theme.shared';

@Component({
  selector: 'app-card-demo',
  imports: [
    CardComponent,
    CardHeaderComponent,
    CardBodyComponent,
    CardTitleDirective,
    CardFooterComponent
  ],
  template: ` 
    <abp-card class="text-center">
      <abp-card-header>Featured</abp-card-header>
      <abp-card-body>
        <h5 abpCardTitle>Special title treatment</h5>
        <p class="card-text">
          With supporting text below as a natural lead-in to additional content.
        </p>
        <a class="card-link" href="#" class="btn btn-primary">Go somewhere</a>
      </abp-card-body>
      <abp-card-footer class="text-muted">
        2 days ago
      </abp-card-footer>
    </abp-card>
  `,
})
export class CardDemoComponent {}

See the header and footer result below: