Skip to content

Instantly share code, notes, and snippets.

@fredchu
Created March 19, 2015 16:10
Show Gist options
  • Select an option

  • Save fredchu/c0a1f64b729720b543e0 to your computer and use it in GitHub Desktop.

Select an option

Save fredchu/c0a1f64b729720b543e0 to your computer and use it in GitHub Desktop.
Demo AngularJS
<!doctype html>
<html ng-app="todoApp">
<head>
<meta charset="UTF-8">
<title>Pinkoi Dev Sharing AngularJS Demo</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
</head>
<body ng-controller="todoController">
<h1>Todos count: <span>{{todos.length}}</span></h1>
<ul id="list">
<li ng-repeat="todo in todos">{{todo}}</li>
</ul>
<form id="form-todo" ng-submit="addTodo($event)">
<input id="form-input" ng-model="todoContent" type="text">
<input type="submit" value="Add a Todo">
</form>
<script>
angular.module('todoApp', [])
.controller('todoController', ['$scope', function($scope) {
$scope.todos = [
'test'
];
$scope.addTodo = function($event) {
$event.preventDefault();
if (!$scope.todoContent) {
return false;
}
$scope.todos.push($scope.todoContent);
$scope.todoContent = '';
};
}]);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment