Skip to content

Instantly share code, notes, and snippets.

@ldiego08
Created April 10, 2014 03:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ldiego08/10341032 to your computer and use it in GitHub Desktop.
Save ldiego08/10341032 to your computer and use it in GitHub Desktop.
JSApps 101: Basic AngularJS Data Binding
var toDoListApp = angular.module('ToDoListApp', []);
toDoListApp.controller('ToDoListController', function ($scope) {
/* Model */
$scope.items = [
{desc: 'Go shopping', done: false},
{desc: 'Clean my room', done: true},
{desc: 'Sleep', done: false}
];
$scope.newItemDescription = '';
/* Events */
$scope.addItem = function () {
$scope.items.push({
desc: $scope.newItemDescription,
done: false
});
};
});
<!doctype html>
<html lang="en" ng-app="ToDoListApp">
<head>
<meta charset="utf-8">
<title>To-do List</title>
<script src="http://code.angularjs.org/1.2.9/angular.min.js"></script>
<script src="app.js"></script>
</head>
<body ng-controller="ToDoListController">
<h1>To-do List</h1>
<ul>
<li ng-repeat="item in items">
{{item.desc}}
</li>
</ul>
<p>
<input type="text" ng-model="newItemDescription" /></input><button ng-click="addItem()">Add</button>
</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment