AngularJS: The First Steps at StartApp - FadiZahhar/AngularJs GitHub Wiki
Sara, Mike, and Lina are back at their desks at StartApp. After their weekend experiment, they want to understand what makes AngularJS so useful, and how to get their hands dirty with a real example.
Sara (reading docs): “So, AngularJS is a JavaScript framework made by Google. It lets us extend HTML with new features, like automatically updating data in our page.”
Mike: “Right. I’ve seen how it makes web apps dynamic—like those real-time dashboards and search bars that filter as you type.”
Lina: “I just want our UI to feel modern! If AngularJS helps, I’m all in.”
- Sara: “It saves us time. We don’t need to write a ton of JS to sync the UI with data.”
- Mike: “It supports two-way data binding. Changes in the UI or data update each other—no fuss.”
- Lina: “Less manual work means fewer bugs and a cleaner design.”
The team decides to follow the basic “Hello AngularJS” example to see how it works:
1. Add the AngularJS Library
Sara grabs the CDN:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
2. Mark the Application with ng-app
In their index.html
:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
</head>
<body>
<div ng-app>
<!-- Angular will take control here -->
</div>
</body>
</html>
3. Use Data Binding
They add a quick binding for a math operation:
<div ng-app>
<p>4 + 6 = {{ 4 + 6 }}</p>
</div>
Result: The page shows 4 + 6 = 10
Sara:
“That’s cool! No JavaScript in the script tag at all.”
Sara experiments more. She adds a text input and a data-bound message:
<div ng-app>
<input ng-model="user">
<h1>Hello {{ user }}</h1>
</div>
Lina types: “Lina” Result: The heading says “Hello Lina” in real time.
Mike wants to see if it works with variables:
<div ng-app ng-init="quantity=3; price=12">
<p>Total = {{ quantity * price }}</p>
</div>
Result: The page shows Total = 36
-
Sara: “With AngularJS, our HTML can show calculations, variables, and even update in real-time, just by using
{{ }}
.” - Mike: “And we don’t have to touch the DOM or write event listeners for every little thing.”
- Lina: “This will make the UI so much more dynamic, and it’ll be easier for us to experiment with new ideas.”
The team asks:
Can you make a mini calculator? Try using two inputs (with
ng-model
) forx
andy
, and show the sum below.
Sara codes:
<div ng-app>
<input ng-model="x" placeholder="First number">
<input ng-model="y" placeholder="Second number">
<p>Sum: {{ x * 1 + y * 1 }}</p>
</div>
(Note: * 1
turns the values into numbers, not strings.)
- AngularJS helps our team quickly build dynamic, real-time features.
- We can keep our HTML clean, readable, and powerful.
- Even beginners like Sara can experiment and see instant results.
Mike says, “Let’s look into how we can organize more complex logic. I see there’s something called ‘Controllers’ coming up…”
Sara grins, “This is fun—let’s keep going!”