Created
April 10, 2014 03:47
-
-
Save ldiego08/10341032 to your computer and use it in GitHub Desktop.
JSApps 101: Basic AngularJS Data Binding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}); | |
}; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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