angular.module('flapperNews', ['ui.router'])
.config([
'$stateProvider',
'$urlRouterProvider',
function($stateProvider, $urlRouterProvider) {

  $stateProvider
    .state('home', {
      url: '/home',
      templateUrl: '/home.html',
      controller: 'MainCtrl'
    });

  $urlRouterProvider.otherwise('home');
}])

.factory('posts', [function(){
  var o = {
    posts: []
  };
  return o;
}])

.controller('MainCtrl', [
'$scope',
'posts',
function($scope, posts){
  $scope.posts = posts.posts;
  $scope.addPost = function() {
    if(!$scope.title || $scope.title === '') { return; }
    $scope.posts.push({
      title: $scope.title,
      link: $scope.link,
      upvotes: 0});
    $scope.title = '';
    $scope.link = '';
  };
  $scope.incrementUpvotes = function(post) {
    post.upvotes += 1;
  };
}]);



@@ -265,16 +265,137 @@
    %7D);%0A%0A
+    .state('posts', %7B%0A      url: '/posts/%7Bid%7D',%0A      templateUrl: '/posts.html',%0A      controller: 'PostsCtrl'%0A    %7D);%0A%0A
   $urlRo
@@ -426,16 +426,16 @@
 home');%0A
-
 %7D%5D)%0A%0A.fa
@@ -791,16 +791,188 @@
 votes: 0
+,%0A      comments: %5B%0A        %7Bauthor: 'Joe', body: 'Cool post!', upvotes: 0%7D,%0A        %7Bauthor: 'Bob', body: 'Great idea but everything is wrong!', upvotes: 0%7D,%0A%0A      %5D%0A    
 %7D);%0A    
@@ -1096,9 +1096,117 @@
 ;%0A%7D%5D);%0A%0A
+.controller('PostsCtrl', %5B%0A'$scope',%0A'$stateParams',%0A'posts',%0Afunction($scope, $stateParams, posts) %7B%0A%0A%7D%5D);%0A
 %0A

add post page draft