By Henk Bakker
It's a structural framework for dynamic web apps
that's easy to maintain, in a fast and testable
way.
<!DOCTYPE html>
<html ng-app>
<head>
<script src="js/angular.min.js"></script>
</head>
<body>
<form>
<label>Your name?</label>
<input type="text" ng-model="name" placeholder="Your name?">
</form>
<h3>My name is {{ name }}!</h3>
</body>
</html>
$scope is an object that refers to the application model.
It connects the View and the Controller, also called ViewModel
myController.js
function MyController($scope) {
$scope.name = 'Henk Bakker';
}
myView.html
<form ng-controller="MyController">
<input type="text" ng-model="name">
</form>
The controller is a function that augment the $scope object.
It's used to add a value or to add a behavior to the $scope.
function TodoCtrl($scope) {
$scope.todos = [
{ text: 'Learn AngularJS', done: true },
{ text: 'Create an App', done: false }
];
$scope.addTodo = function () {
$scope.todos.push({ text: $scope.todoText, done: false });
$scope.todoText = '';
};
};
"Teach new tricks to the HTML"
All the attributes that begin with "ng" are AngularJS directives.
How to use directives
<!doctype html>
<html ng-app="myApp">
<head>
<script src="../js/angular.min.js"></script>
</head>
<body>
<ul ng-controller="myListController">
<li ng-repeat="item in items">
{{ item.name }}
</li>
</ul>
</body>
</html>
You can also create you own directive.