AngularJS – My First Hello World tutorial


I am using AngularJS from a while now and decided to write a series of post on AngularJS now. I will start with a basic Hello World post which mostly focuses on how to setup environment for AngularJS to use it. Later I will gradually cover up all (or most of) important concepts on AngularJS and then we will how to integrate AngularJS with other tools and frameworks (like Spring MVC, Laravel, etc).

What is AngularJS ?

AngularJS is an open-source web-based JavaScript framework developed to make easier to implements Single Page Application (SPA). It’s developed and maintained by Google and community of developers and the goal is to simplify development and testing of client side web application.

AngularJS Hello World

Follow the simple steps to create your first AngularJS application.

Step 01)

First step is to include angularjs javascript file into your HTML document. You can download the complete AngularJS from https://angularjs.org site but for this tutorial i recommend you to use CDN url as below.

Step 02)

Second step is to create an angular module and define a Controller. The job of controller is to control the information that we put on page or in editing scenario controller save the information that use is typing into the page.

I am creating a separate javascript file and add the angular code.

As you can see in about code snippet, I called module() function of angular global variable and pass the module name. This module has function call controller() which we can use to define our first HelloController.

As you can see in above code snippet, controllers are just functions. We don’t invoke this functions but angular will call this controller function when it need to manage the section of HTML page which has ng-controller directive. When Angular create controller, it pass the parameter to function called $scope. We can attached our models or data to this $scope variable.

Step 03)

To use the controller on page, we need to use a directive called ng-controller. Its an attribute which place in HTML and used to controller some area in HTML document.

Remember, $scope is not the model but the things that we attached to it is the model. In the above code snippet we only attached a single property to the $scope called message which points to a string value. This one will make message available to us inside HTML so we can data bind into display.

Output

I hope you enjoy the post, there are lot of post on AngularJS to come in future so stay tuned.

About the Author

has written 68 posts.

I Love Coding, Analyzing, Designing and doing it the right way. I am obsessed about learn anything new daily and sharing what I have learn each Day. This Blog is journey of my Zeal, going through step by step to the mountain of desire to become prefect. Google Wanna Hire me ?

Copyright © 2017 TechZoo - Technology Blog. All rights reserved.
Proudly powered by WordPress. Developed by 7Tech Solutions