On Github bwolvin / Angular
<html ng-app> <head> <script src="http://code.angularjs.org/angular-1.0.0rc10.min.js"></script> </head> <body> <div> <label>Name:</label> <input type="text" ng-model="yourName" placeholder="Enter a name here"> <hr> <h1>Hello, {{yourName}}!</h1> </div> </body> </html>
Add the ng-app directive to the tag
< html lang='en' ng-app>
Add the Angular < script > tag to the end of your tag:
<head>...meta and stylesheet tags... <script src="lib/angular/angular.js" ></script>
The name of the Javascript class in the controller tells Angular what code to run
<div ng-controller="TodoCtrl">
ng-repeat is a repeater directive that loops through the current collection and does the specified action
<ul class="unstyled"> <li ng-repeat="todo in todos"> <input type="checkbox" ng-model="todo.done"> <span class="done-{{todo.done}}">{{todo.text}}</span> </li> </ul>
function TodoCtrl($scope) { $scope.todos = [ {text:'learn angular', done:true}, {text:'build an angular app', done:false}]; $scope.remaining = function() { var count = 0; angular.forEach($scope.todos, function(todo) { count += todo.done ? 0 : 1; }); return count; }; }
.done-true { text-decoration: line-through; color: grey; }
<form ng-submit="addTodo()"> <input type="text" ng-model="todoText" size="30" placeholder="add new todo here"> <input class="btn-primary" type="submit" value="add"> </form>
$scope.addTodo = function() { $scope.todos.push({text:$scope.todoText, done:false}); $scope.todoText = ''; };