<repo_name>herpiko/kelasglib-mean-stack-II-angularjs<file_sep>/src/exercise_3/app.js
var app = angular.module('App', ['ui.router'])
.config(function($stateProvider){
  $stateProvider
  .state('Main', {
    url : '/main',
    templateProvider : function($templateCache) {
      return $templateCache.get('main.html');
    }
  })
  .state('About', {
    url : '/about',
    template : '<div>Hello</div>' 
    /* function($templateCache) { */
    /*   return $templateCache.get('about.html'); */
    /* } */
  })
})
.controller('MainController', function($rootScope, $scope){
  $scope.title = 'Main Page';
  $scope.body = 'Velit ut exercitationem quia et laborum ea. Autem ea est et sed. Molestiae vel non modi temporibus quo enim.';
})
.controller('AboutController', function($rootScope, $scope){
  $scope.title = 'About Page';
  $scope.body = 'Tentang kami, ...';
})
.run(['$state', function($state){
  $state.go('Main');
}])
<file_sep>/src/exercise_5/app.js
var app = angular.module('App', ['ui.router']);
app.config(function($stateProvider){
  $stateProvider
  .state('Main', {
    url : '/main',
    templateProvider : function($templateCache) {
      return $templateCache.get('main.html');
    }
  })
  .state('New', {
    url : '/new',
    templateProvider : function($templateCache) {
      return $templateCache.get('new.html');
    }
  })
  .state('Detail', {
    url : '/detail/{id}',
    templateProvider : function($templateCache) {
      return $templateCache.get('detail.html');
    }
  })
})
/* .directive('item', function(){ */
/*   return function(sco */
/* }) */
.service('CrudService', function($http){
  this.list = function() {
    return $http.get('http://localhost:3000/folks');
  }
  this.get = function(id) {
    return $http.get('http://localhost:3000/folks/' + id);
  }
  this.create = function(data) {
    return $http.post('http://localhost:3000/folks', JSON.stringify(data));
  }
  this.delete = function(id) {
    return $http.delete('http://localhost:3000/folks/' + id + '/edit');
  }
  this.update = function(data) {
    return $http.put('http://localhost:3000/folks/' + data._id + '/edit', data);
  }
})
.controller('MainController', function($rootScope, $scope, CrudService, $state){
  $scope.title = 'Main Page';
  $scope.list = [];
  $scope.reload = function(){
    CrudService.list()
    .then(function(result){
      $scope.list = result.data;
    })
  }
  $scope.reload();

  $scope.delete = function(id){
    CrudService.delete(id)
    .then(function(result) {
      $scope.reload(); 
    })
  }
  $scope.detail = function(id) {
    $state.go('Detail', { id: id } )
  }
})
.controller('NewController', function($rootScope, $scope, CrudService, $state){
  $scope.title = 'New item';
  $scope.save = function(data) {
    CrudService.create(data)
    .then(function(result){
      $state.go('Main');  
    })
  }
})
.controller('DetailController', function($rootScope, $scope, $stateParams, CrudService){
  $scope.title = 'Detail';
  var id = $stateParams.id;
  CrudService.get(id)
  .then(function(result){
    $scope.data = result.data;
  })
  .catch(function(result){
    // Handle error
    console.log(result.data);
  })
})
.run(['$state', function($state){
  $state.go('Main');
}])
<file_sep>/src/exercise_4/app.js
var app = angular.module('App', ['ui.router'])
.config(function($stateProvider){
  $stateProvider
  .state('Main', {
    url : '/main',
    templateProvider : function($templateCache) {
      return $templateCache.get('main.html');
    }
  })
  .state('Todo', {
    url : '/todo',
    templateProvider : function($templateCache) {
      return $templateCache.get('todo.html');
    }
  })
})
.controller('MainController', function($rootScope, $scope){
  $scope.title = 'Main Page';
})
.controller('TodoController', function($rootScope, $scope){
  $scope.list = []; 
  // $scope.list = ['ary', 'dendy']
  $scope.listObj = [
    {
      nama : 'Ary',
      usia : 20
    },
    {
      nama : 'Irwan',
      usia : 21
    },
  ]
  $scope.title = 'Todo List';
  $scope.add = function(data) {
    if (!data) {
      return alert('Mana sih datanya');
    }
    $scope.list.push(data);
    $scope.new = '';
  }
  $scope.delete = function(index) {
    $scope.list.splice(index, 1);
  }
})
.run(['$state', function($state){
  $state.go('Todo');
}])
