Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Bootstrap AngularJS into a Static HTML file


    In this lesson, we learn how to take a static HTML page and tap into the power of AngularJS by bootstrapping the framework.



    Become a Member to view code

    You must be a Pro Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    orLog In




    Man: Welcome to the first video of the Eggly series. In this video I'm going to show you how to take a static HTML page and bootstrap it into a working AngularJS application.

    The first thing that we need to do to get AngularJS working in the page is to add in the AngularJS JavaScript file. Let's hop over to AngularJS.org. We'll scroll down to the bottom to the download button. I'm going to just grab the latest stable version, which is 1.2.20. I'm going to copy that.

    From there, we will hop into the code into index.start.html, scroll down to the bottom. I'm going to duplicate this last include here and then paste in the reference to the AngularJS JavaScript file.

    What we have here is jQuery, bootstrap, Lo-Dash, which we're going to use for some collection manipulation and for the videos. Then the minified version of AngularJS.

    To get started, for the sake of illustration I am going to initialize a variable using ngInit. I'm going to say, "Hello=world." From here, I'm going to create a big H1 tag. Using double curly brace syntax, I'm going to put "Hello" in there.

    And so, when I refresh the page, and this to prove or to show that AngularJS is not working. Then we will hook it up so it is working. Refresh and then you get this big Hello and these double curly braces. Nothing is happening at the moment.

    To actually get this to render, we will go up to the HTML tag and we will add in the ngApp attribute. How this works is when the page loads and the AngularJS JavaScript file is loaded it scans the dom and looks for this ngApp attribute on any of the elements. When it finds it, it will initialize an AngularJS application to that element and its children.

    In this case, the app is initialized into the HTML tag and everything underneath it. In this case, pretty much everything.

    Let's go back and refresh the page. You can see now that {{Hello}} is being evaluated to World. Now we have a working AngularJS application.

    I'll take this one step further. Let's go ahead and add in an input field. We're going to say this is text. We're going to bind this to Hello. We're saying ngModel=Hello.

    Refresh the page and from here when I actually start typing because the AngularJS application has been initialized when I change it in one place it changes it in the other place. This is the beauty and the power of AngularJS is that you're now basically extracting the model out from the dom.

    We're going to elaborate on this concept in the next video where I introduce a controller into the application. We will actually hook up categories and bookmarks and make those dynamic.

    Thanks for sticking around for this video. I will see you in the next one.