Skip to content

Instantly share code, notes, and snippets.

@bcuz
Created September 16, 2016 16:23
Show Gist options
  • Save bcuz/eab6c1dff19f86dd263dcff2d2da5623 to your computer and use it in GitHub Desktop.
Save bcuz/eab6c1dff19f86dd263dcff2d2da5623 to your computer and use it in GitHub Desktop.
app.controller('HomeController', ['$scope', 'suggestions', function($scope, suggestions) {
$scope.posts = suggestions.posts;
$scope.addSuggestion = function(index) {
if ($scope.title === "" | !$scope.title) {
return
}
$scope.posts.push({
title: $scope.title,
upvotes: 0,
comments: [],
})
$scope.title = "";
};
$scope.upVote = function(post) {
post.upvotes += 1;
};
}]);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
<link rel="stylesheet" href="css/main.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>
<script src="https://code.angularjs.org/1.2.28/angular-route.min.js"></script>
</head>
<body ng-app="SuggestionBox" ng-controller="HomeController">
<div ng-view></div>
<form ng-submit="addSuggestion()" style="margin-top: 50px">
<h3> Submit Your Suggestion </h3>
<div class="form-group">
<input type="text" class="form-control" placeholder="Great ideas here" ng-model="title"></input>
</div>
<button type="submit" class="btn btn-primary">Suggest</button>
</form>
<!-- Modules -->
<script type="text/javascript" src="js/app.js"></script>
<!-- Controllers -->
<script type="text/javascript" src="js/controllers/HomeController.js"></script>
<script type="text/javascript" src="js/controllers/SuggestionController.js"></script>
<!-- Services -->
<script src="js/services/suggestions.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment