Want to help the fight against COVID-19? Take part in this virtual quiz night fundraiser on April 25th, 5pm EST.

AngularJS Tutorial Part 4: Introducing Bootstrap

August 20, 2016

This is part 4 of a multi-part Intro to AngularJS tutorial series. Part 3 can be found here, and Part 5 can be found here.

Since AngularJS uses HTML based views, it’s extremely easy to add styling to your pages. I’ll use Bootstrap to turn what we’ve made so far look a little nicer. Bootstrap is pretty easy to setup, however there are many other options when it comes to styling pages, for example using Material Design.

The first step is to include all the necessary Bootstrap files. I’ll be using the hosted CDN files, and include those into the ‘index.html’ file, however you can also use other techniques like Bootstrap as a directive or BootstrapJS.

<!-- Bootstrap -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

Now for some Bootstrapping fun! We’ll change the header, then make each character into their own div, and turn the movie names into buttons (we’ll make these clickable buttons in the next section).

<div class="col-md-10 col-md-offset-1">
  <div class="page-header">
    <h1>Star Wars</h1>

  <div class="panel panel-default" ng-repeat="person in data">
    <div class="panel-heading">{{ person.name }}</div>
    <div class="panel-body">
      <ul class="btn-group" ng-repeat="film in person.films">
        <button class="btn btn-primary">
          {{ films[film] }}

Doesn’t that look a lot better?

AngularJS Tutorial Styling the Website Using Bootstrap

If you think you’ve made a mistake somewhere, you can access a copy of the above code from the accompanying github repository. Click here to see all the code upto the end of this section.