Bootstrap Table Styling in Angular 8 & ASP.NET Core

Updated on Oct 03,2025

Table of Contents

In this comprehensive guide, you'll learn how to elevate the visual appeal of your Angular 8 and ASP.NET Core applications by leveraging Bootstrap's powerful table styling features. From user grids to interactive action columns, we'll walk you through the steps to create a more engaging and user-friendly interface. This tutorial is designed for developers who want to add a touch of elegance and professionalism to their data displays, focusing on the integration of Bootstrap's pre-built components for a seamless user experience.

Key Points

Integrate Bootstrap table styles in Angular 8 components.

Define columns for user data like first name, last name, email, and mobile number.

Add an actions column for user management options.

Inject user services in Angular for data retrieval.

Utilize TypeScript to define data models and service dependencies.

Implement Bootstrap styling using HTML templates.

Incorporate ngFor loops for dynamic data rendering.

Explore creating new components for edit and delete actions.

Creating User Grids with Bootstrap Styling

Why Use Bootstrap for Table Styling?

Bootstrap provides a sleek, responsive, and consistent way to style HTML tables. Its pre-defined classes make it easy to implement professional-looking data grids without writing extensive custom CSS. For Angular 8 and ASP.NET Core applications, using Bootstrap can save time and effort while ensuring a user-friendly display of information. Bootstrap styling is an essential technique for modern web development, and mastering it can significantly enhance the aesthetics and usability of your projects.

By using bootstrap styling, developers can ensure their web applications have a polished and professional look, which is crucial for user engagement and satisfaction. This is especially important in data-driven applications where tables are the primary means of displaying information.

Setting Up the Angular Component

To begin, we need to set up an Angular component dedicated to managing our users. This component will fetch user data from an ASP.NET Core API and display it in a Bootstrap-styled table. First, ensure you have the Angular CLI installed and create a new component using the following command:

ng generate component manage-users

This will generate the necessary files, including the component's TypeScript file, HTML template, and CSS file.

Once created, the next step is to navigate the Bootstrap official website and copy the basic table code:

<table class="table">
  <thead>
    <tr>
      <th scope="col">#</th>
      <th scope="col">First</th>
      <th scope="col">Last</th>
      <th scope="col">Handle</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th scope="row">1</th>
      <td>Mark</td>
      <td>Otto</td>
      <td>@mdo</td>
    </tr>
    <tr>
      <th scope="row">2</th>
      <td>Jacob</td>
      <td>Thornton</td>
      <td>@fat</td>
    </tr>
    <tr>
      <th scope="row">3</th>
      <td>Larry</td>
      <td>the Bird</td>
      <td>@twitter</td>
    </tr>
  </tbody>
</table>

Next, update the table headers to reflect the data we want to display, such as 'First Name', 'Last Name', 'Email', and 'Mobile Number'. We'll also add an 'Actions' column for user management options. This involves modifying the HTML template file (manage-users.component.html) to include these specific columns.

Defining the Table Columns

The first step is to define the table columns that will display the user data. These columns include:

  • First Name: Displays the user's first name.

  • Last Name: Displays the user's last name.

  • Email: Displays the user's email address.

  • Mobile Number: Displays the user's mobile number.

  • Actions: Contains buttons for editing and deleting users. In the manage-users.component.html file, update the <th> elements in the <thead> section to match these columns.

<table class="table table-striped">
  <thead>
    <tr>
      <th scope="col">#</th>
      <th scope="col">First Name</th>
      <th scope="col">Last Name</th>
      <th scope="col">Email</th>
      <th scope="col">Mobile Number</th>
      <th scope="col">Actions</th>
    </tr>
  </thead>
  <tbody>
  </tbody>
</table>

This setup provides a clear structure for our user grid, preparing it for the dynamic data rendering we'll implement next. The 'actions' columns sets the base table layout.

Creating User Service and TypeScript setup

To dynamically populate the table, we need to retrieve user data from an external source, typically an ASP.NET Core API. First, create a user service in Angular using the Angular CLI:

ng generate service users

This generates users.service.ts and related files. Then, inject the HttpClient into the UserService to make HTTP requests. Update the service to include a method that fetches user data from your API:

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { User } from './user.model';

@Injectable({
  providedIn: 'root'
})
export class UsersService {
  private baseUrl = 'https://localhost:4200/api';

  constructor(private http: HttpClient) { }

  getUsers(): Observable<User[]> {
    return this.http.get<User[]>(`${this.baseUrl}/users`);
  }
}

This service provides a getUsers method that returns an Observable of type User[], allowing us to handle asynchronous data fetching. Make sure you have installed HTTPClientModule in the project: npm install --save @angular/http. To utilize the new injected service, include the following in constructor: private userService: UsersService

The last step here is to make an action to load Users: this.userService.getUsers()

Loading Users Into the Component

Now that we have the user service set up, we can inject it into our ManageUsersComponent to retrieve user data. Import the UsersService into your component and inject it into the constructor:

import { Component, OnInit } from '@angular/core';
import { UsersService } from '../users.service';
import { User } from '../user.model';

@Component({
  selector: 'app-manage-users',
  templateUrl: './manage-users.component.html',
  styleUrls: ['./manage-users.component.scss']
})
export class ManageUsersComponent implements OnInit {
  users: User[] = [];

  constructor(private userService: UsersService) { }

  ngOnInit() {
    this.userService.getUsers().subscribe(users => {
      this.users = users;
    });
  }
}

This code fetches the user data in the ngOnInit lifecycle hook and assigns it to the users property of the component. Now, we can use this data to populate our table. By doing the above, we have populated users list: users: User[] = [];

This initializes users list which will later be displayed by following ngFor method.

Populating the Table with User Data

With the user data now available in the component, we can use Angular's *ngFor directive to iterate over the users array and generate table rows dynamically. Update the <tbody> section of your manage-users.component.html file as follows:

<tbody>
  <tr *ngFor="let user of users; let i = index">
    <th scope="row">{{ i + 1 }}</th>
    <td>{{ user.firstName }}</td>
    <td>{{ user.lastName }}</td>
    <td>{{ user.email }}</td>
    <td>{{ user.mobileNumber }}</td>
    <td>
      <button class="btn btn-primary btn-sm">Edit</button>
      <button class="btn btn-danger btn-sm">Delete</button>
    </td>
  </tr>
</tbody>

This code iterates through the users array, creating a new table row for each user. The {{ i + 1 }} expression displays the row number, and the other {{ user.propertyName }} expressions display the corresponding user data.

Now, let’s add M-2 class to have margin in both “Edit” and “Delete” buttons

Adding Action Columns (Edit and Delete)

The final touch is to add action buttons to each row, allowing users to edit or delete the corresponding user. We've already included the basic button structure in the previous HTML snippet. Now, let's add some basic styling and functionality. Add an “ngIf” condition in order to prevent errors: *ngIf="userList".This form is now complete: user first, last name, email, mobile number and two actions. [t: 501]This is crucial for implementing any data-driven features and providing a clear path for any functionality related to each user shown.

Step-by-Step Guide

Setting up project

This guide will walk you through the process of setting up the project. First, you must install Angular on your computer. Make sure your Angular version is 8.

Getting Bootstrap

The most important thing is to connect the new project with Bootstrap.

FAQ

How can I customize the Bootstrap table styles?
You can override the default Bootstrap styles by adding custom CSS classes to your component's SCSS file. For more advanced customization, consider exploring Bootstrap's theming options.
What if my API returns data in a different format?
You may need to transform the data using RxJS operators like map or pluck in your service to match the User model defined in your Angular component.
How do I handle errors when fetching data from the API?
Use RxJS operators like catchError in your service to handle HTTP errors gracefully. Display an error message to the user and log the error for debugging purposes.

Related Questions

What are common challenges when integrating Bootstrap into Angular projects, and how can they be addressed?
One common issue is CSS conflicts, where Bootstrap styles inadvertently affect other parts of the application. Using CSS modules or Shadow DOM can help isolate styles. Also, ensure Bootstrap's JavaScript components don't conflict with Angular's lifecycle hooks by using Angular-specific libraries like ng-bootstrap or Angular Material for component implementations. It’s also crucial to manage dependencies carefully, ensuring all libraries are compatible and correctly imported into the project to prevent runtime errors or style inconsistencies. Thorough testing and adherence to best practices for Angular component design can further mitigate these challenges.

Most people like