Skip to content

Instantly share code, notes, and snippets.

@rachaelshaw
Created July 2, 2015 02:41
Show Gist options
  • Save rachaelshaw/82f0e1d6e7ee8e4dfd38 to your computer and use it in GitHub Desktop.
Save rachaelshaw/82f0e1d6e7ee8e4dfd38 to your computer and use it in GitHub Desktop.
angular.module('TreelineExample').controller('AppCtrl', [
'$scope', '$timeout', '$http',
function ($scope, $timeout, $http){
console.log('running!');
$scope.homepage = {};
$scope.homepage.messageSent = false;
$scope.sendmessage = function() {
// Clear out error list
$scope.errors = [];
$scope.homepage.messageSent = false;
// Check for errors
if(!$scope.name) {
$scope.errors.push('name');
}
if(!$scope.email) {
$scope.errors.push('email');
}
if(!$scope.message) {
$scope.errors.push('message');
}
// If no errors, go ahead and submit.
if(!$scope.errors.length) {
// Show loading state
$scope.syncing = true;
// Submit
$http.post('/contact', {
name: $scope.name,
email: $scope.email,
message: $scope.message
})
.then(function(){
// Clear out form
$scope.name = '';
$scope.email = '';
$scope.message = '';
// Show thank you message
$scope.homepage.messageSent = true;
// Clear loading state
$scope.syncing = false;
})
.catch(function(err){
console.log(err);
});
}
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment