Enter Your Email Address to Watch This Lesson

Your link to unlock this lesson will be sent to this email address.

Unlock this lesson and all 832 of the free egghead.io lessons, plus get Angular 1.x content delivered directly to your inbox!



Existing egghead members will not see this. Sign in.

Just one more step!

Check your inbox for an email from us and click link to unlock your lesson.



First Step: Adding Angular to the HTML Page

2:51 Angular 1.x lesson by

The first step to any AngularJS project, is actually adding AngularJS to the page. This lesson will show you adding the Angular script, initializing the app with ng-app, and simple two way binding with ng-model. This is a beginner level lesson.

Get the Code Now
click to level up

egghead.io comment guidelines

Avatar
egghead.io

The first step to any AngularJS project, is actually adding AngularJS to the page. This lesson will show you adding the Angular script, initializing the app with ng-app, and simple two way binding with ng-model.

Lukas Ruebbelke: Hello. This is Lukas Ruebbelke. In this video, I'm going to show you how to actually add in AngularJS to your webpage. What I have here is a completely blank page that doesn't have a lot going on in it.

The first thing that we need to do is to actually include the AngularJS JavaScript file. If you go to angularjs.org and you click on this "Download" button, you can choose the version that you want to actually include in your page.

Let's just grab the latest. We will just copy the CDN link here, and then we'll hop back into our code. We'll just add this at the bottom. I'm just going to paste this in.

From here, we are ready to actually instantiate an AngularJS application. On the HTML tag, I'm going to just put "ng-app" to say, "I want this entire HTML page to be an AngularJS application."

Then, in the body tag, I'm going to create a big, bold H1 tag. I'm going to just bind this to a property called "hello." Then I'm going to create an input field, and I'm going to set this to "ng-model = "hello"."

The idea is when I change "hello" in the input field, it will change the value in the H1 tag. I'm doing this to show that the AngularJS application is indeed initializing and spinning up.

Let's jump into the page. Let's refresh this. There's nothing in the input field now, so we are not seeing the H1 tag. As I start to type, you can see that it is updating in real-time. This is how you know the AngularJS application is indeed working.

Just to summarize, we have added in the AngularJS file, to our page, using the script tag. Then we instantiated the AngularJS application using ng-app.

Then we bound to a simple value using ng-model and the {{ binding syntax. You can see this living in the page. This is how you get AngularJS into your application.

This is the very first step when using AngularJS. Check out the other egghead videos to learn more advanced topics on AngularJS. Catch you next time.

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?