# MEAN Stack Part 2
## Lesson Objectives
1. Create a function to get all todos
1. On page load, show all todos
1. After creating a new todo, refresh list of todos
1. Clicking on a todo toggles it complete/incomplete
1. Create a delete button
1. Edit the Todo
## Create a function to get all todos
public/js/app.js:
```javascript
this.getTodos = function(){
$http({
method:'GET',
url: '/todos',
}).then(function(response){
console.log(response);
}, function(){
console.log('error');
});
};
this.getTodos(); //call immediately once controller is instantiated to test
```
## On page load, show all todos
1. create `controller` variable set to `this`
1. set property one controller when ajax succeeds
1. call getTodos during controller instantiation
public/js/app.js:
```javascript
app.controller('MyController', ['$http', function($http){
this.description = null;
this.complete = false;
const controller = this; //create controller var
//...farther down the page
this.getTodos = function(){
$http({
method:'GET',
url: '/todos',
}).then(function(response){
controller.todos = response.data; //set value on success
}, function(){
console.log('error');
});
};
this.getTodos(); //call immediately once controller is instantiated
}]);
```
public/index.html:
```html
{{todo.description}}
```
1. `mkdir public/css`
1. `touch public/css/app.css`
public/css/app.css:
```css
.complete {
text-decoration: line-through;
}
```
public/index.html:
```html
```
## After creating a new todo, refresh list of todos
public/js/app.js:
```javascript
$http({
method:'POST',
url: '/todos',
data: {
description: this.description,
complete: this.complete
}
}).then(function(response){
controller.getTodos(); //get all todos when new element is added
}, function(){
console.log('error');
});
```
## Clicking on a todo toggles it complete/incomplete
public/index.html:
```html