Created
July 2, 2015 02:41
-
-
Save rachaelshaw/82f0e1d6e7ee8e4dfd38 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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