Skip to content

Instantly share code, notes, and snippets.

@mekhami
Created December 2, 2015 19:23
Show Gist options
  • Select an option

  • Save mekhami/ff1fa745ca673babcb24 to your computer and use it in GitHub Desktop.

Select an option

Save mekhami/ff1fa745ca673babcb24 to your computer and use it in GitHub Desktop.
var app = angular.module('myApp', []);
app.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
$routeProvider.
when('/', {
templateUrl: '../views/codeform.html',
controller: 'MainController'
}).
when('/confirm', {
templateUrl: '../views/confirm.html',
controller: 'ConfirmController'
});
$locationProvider.html5Mode(true);
}]);
app.factory('rsvpDataService', function($http, $q) {
var service = {};
service.getRsvp = function(code) {
var deferred = $q.defer();
$http.get('/api/rsvps/'+code)
.success(function(data) {
deferred.resolve(data);
})
.error(function(data) {
deferred.reject('There was an error')
});
return deferred.promise;
};
return service;
});
app.controller('ConfirmController', ['$scope', '$http', function($scope, $http) {
}]);
app.controller('MainController', ['$scope', '$http', 'rsvpDataService', function($scope, $http, rsvpDataService) {
$scope.formData = {};
$scope.rsvp = {};
$scope.createRsvp = function() {
rsvpDataService.getRsvp($scope.formData.code)
.then(function(data) {
$scope.rsvp = data;
console.log($scope.rsvp);
}, function(data) {
console.log('does this get run?')
})
}
$scope.deleteRsvp = function(code) {
$http.delete('/api/rsvps/' + code)
.success(function(data) {
$scope.todos = data;
console.log(data);
})
.error(function(data) {
console.log('Error: ' + data);
});
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment