javascript - How to connect Mailchimp subscribers with Firebase using AngularJS -
i have database firebase , i'm trying newsletter subscription, want save subscribers in mailchimp , firebase.
mailchimp connection works perfectly, don't know how integrate firebase connection in same js.
this have in <head>
tag
<script type="text/javascript"> angular.module("productlaunch", ["mailchimp"]) </script>
this in <body>
tag
<body ng-app="productlaunch"><section class="container-fluid subscribe" ng-controller="mailchimpsubscriptionctrl"> <div class="wrapper"> <!-- let email --> <div class=""> <h2 class="text-center">subscribe our news</h2> <div class="col-lg-4 col-lg-offset-4 mt centered"> <h4 ng-hide="mailchimp.result ==='success'">let me know when launch</h4> <h4 ng-show="mailchimp.result ==='success'">thanks signing up!</h4> </div> <form class="form-inline" role="form" ng-hide="mailchimp.result === 'success'"> <input class="hidden" type="hidden" ng-model="mailchimp.username" ng-init="mailchimp.username='stopappweb'"> <input class="hidden" type="hidden" ng-model="mailchimp.dc" ng-init="mailchimp.dc='us12'"> <input class="hidden" type="hidden" ng-model="mailchimp.u" ng-init="mailchimp.u='3eb39be3ad857e60b357fdb5e'"> <input class="hidden" type="hidden" ng-model="mailchimp.id" ng-init="mailchimp.id='520ddfd981'"> <div class="form-group"> <label class="sr-only" for="mailchimp.email">email address</label> <input type="email" class="form-control" id="mailchimp.email" placeholder="enter email" ng-model="mailchimp.email"> </div> <button type="submit" class="btn btn-info" ng-disabled="mailchimpsubscriptionform.$invalid" ng-click="addsubscription(mailchimp)" type="submit" value="sign up" disabled="disabled">submit</button> <div ng-show="mailchimp.result === 'error'"> <p ng-bind-html="mailchimp.errormessage" class="error"></p> </div> </form> </div> </div> </section>
and js:
'use strict'; angular.module('mailchimp', ['ng', 'ngresource', 'ngsanitize']) .controller('mailchimpsubscriptionctrl', ['$log', '$resource', '$scope', function ($log, $resource, $scope) { $scope.mydata = new firebase("https://stopappwebpre.firebaseio.com/subscriptors"); // handle clicks on form submission. $scope.addsubscription = function (mailchimp) { var actions, mailchimpsubscription, params, url; $scope.mydata.push({mailchimp.email:$scope.mailchimp.email}); // create resource interacting mailchimp api url = 'http://' + mailchimp.username + '.' + mailchimp.dc + '.list-manage.com/subscribe/post-json'; params = { 'email': mailchimp.email, 'fname': mailchimp.fname, 'lname': mailchimp.lname, 'c': 'json_callback', 'u': mailchimp.u, 'id': mailchimp.id }; actions = { 'save': { method: 'jsonp' } }; mailchimpsubscription = $resource(url, params, actions); // send subscriber data mailchimp mailchimpsubscription.save( // sent data mailchimp. function (response) { // define message containers. mailchimp.errormessage = ''; mailchimp.successmessage = ''; // store result mailchimp mailchimp.result = response.result; // mailchimp returned error. if (response.result === 'error') { if (response.msg) { // remove error numbers, if any. var errormessageparts = response.msg.split(' - '); if (errormessageparts.length > 1) errormessageparts.shift(); // remove error number mailchimp.errormessage = errormessageparts.join(' '); } else { mailchimp.errormessage = 'sorry! unknown error occured.'; } } // mailchimp returns success. else if (response.result === 'success') { mailchimp.successmessage = response.msg; } }, // error sending data mailchimp function (error) { $log.error('mailchimp error: %o', error); } ); }; }]);
thank help.
Comments
Post a Comment