Data objects:
a string, a JSON file, an API, etc.
Your HTML.
The link between the two:
your JS files, your program.
var myModel = 'Guten Tag Berlin!';
Bonjour Paris
function changeTitle() {
document.getElementById('title').innerHTML = myModel;
}
Angular binds the view and the model instantly:
both ways data-binding
<!doctype html>
<html ng-app>
<head>
</head>
<body>
My name is: {{ name }}
</body>
</html>
You only need one file!
<!doctype html>
<html ng-app>
<head>
</head>
<body>
</body>
</html>
Where variables and functions are accessible, and in what context it is being executed
<script>
var g = "global";
function read() {
var l = "local";
alert(l); // alert "local"
}
read();
alert(l); // throws a reference error
</script>
An object that communicate between
your Controller and your View
ngController directive defines a controller for a div-(or any element)-scope
<body ng-app>
Hello {{ sayHello }}
Hello {{ sayHello }}
</body>
$scope only accesses data within the matching div-scope
function Example2ACtrl($scope) {
$scope.sayHello = 'girls!';
}
function Example2BCtrl($scope) {
$scope.sayHello = 'boys!';
}
How to make the HTML learn new tricks
<body ng-app>
</body>
function Example4Ctrl($scope) {
$scope.pilots = [
{ codename: "Apollo", firstname: "Lee", lastname: "Adama" },
{ codename: "Starbuck", firstname: "Kara", lastname: "Thrace" },
{ codename: "Helo", firstname: "Karl", lastname: "Agathon" },
{ codename: "Kat", firstname: "Louanne", lastname: "Katraine" },
{ codename: "Boomer", firstname: "Sharon", lastname: "Valerii" }
];
}
-
{{ pilot.codename}}
· {{ pilot.firstname }} {{ pilot.lastname }}
function Example3Ctrl($scope) {
$scope.val1 = 0;
$scope.val2 = 0;
}
Next meeting is this Wednesday!
More information @angular_berlin