Skip to content

Instantly share code, notes, and snippets.

@chrisbodhi
Last active August 29, 2015 14:10
Show Gist options
  • Save chrisbodhi/1eba07ef0ac257ccc2eb to your computer and use it in GitHub Desktop.
Save chrisbodhi/1eba07ef0ac257ccc2eb to your computer and use it in GitHub Desktop.
Angular.js form controller used with the KickoffLabs API
app.controller('FormController', function( $scope, $http, $routeParams ){
'use strict';
var self = this,
kickoffId = '99999', // https://app.kickofflabs.com/dashboard/campaigns/36854/api
url,
config,
socialRef,
id;
// Pulls out the slug used for viral sharing
socialRef = $routeParams.socialRef;
self.submit = function (isValid, formData) {
if (!isValid) return;
url = 'https://api.kickofflabs.com/v1/' + kickoffId + '/subscribe';
config = { params: {
email: formData.email,
social_id: socialRef || null,
jsonp: 'JSON_CALLBACK',
__url: 'http://CUSTOM-URL.com' // redirect destination after unsubscribing via email link
}
};
$http.jsonp( url, config )
.success(function(data, status) {
console.log( 'bueno' );
console.log( data );
console.log( status );
// for the viral URL
self.shareId = data.social_id;
})
.error(function(data, status) {
console.log( 'no bueno' );
console.log( data );
console.log( status );
});
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment