0

I have a code

angular.module('ngMailChimp', ['ngAria', 'ngMessages', 'ngAnimate'])
    .controller('SignUpController', function () {
        var ctrl = this,
            newCustomer = { email:'', userName:'', college:'' },
            actions,
            MailChimpSubscription;

        var signup = function () {
            if( ctrl.signupForm.$valid) {
                $http({
                    url: 'http://' + 'campusconnect' + '.' + 'us11' +'.list-manage.com/subscribe/post-json', 
                    method: "GET",
                    params: {NAME: ctrl.newCustomer.userName,
                            COLL : ctrl.newCustomer.college,
                            EMAIL : ctrl.newCustomer.email,
                            u : "35f503a1404877769e67c22f9",
                            id : "d5a2aab2f9"                           }
                });




                //MailChimpSubscription.save(
        // Successfully sent data to MailChimp.
                //function (response) {
                //    if (response.result === 'error')
                //    {
                //        ctrl.showSubmittedPrompt = false;
                //    }
                //    else
                //    {
                //        ctrl.showSubmittedPrompt = true;
                //        clearForm();
                //    }
                //},
                //function (error) {
                //    $log.error('MailChimp Error: %o', error);
                //}
                //);  
                ctrl.showSubmittedPrompt = true;
                clearForm();        
            }
        };

        var clearForm = function () {
            ctrl.newCustomer = { email:'', userName:'', college:'' }
            ctrl.params={}
            ctrl.signupForm.$setUntouched();
            ctrl.signupForm.$setPristine();
        };

        var getPasswordType = function () {
            return ctrl.signupForm.showPassword ? 'text' : 'password';
        };

        var toggleEmailPrompt = function (value) {
            ctrl.showEmailPrompt = value;
        };

        var toggleUsernamePrompt = function (value) {
            ctrl.showUsernamePrompt = value;
        };

        var toggleCollegePrompt = function (value) {
            ctrl.showCollegePrompt = value;
        };

        var hasErrorClass = function (field) {
            return ctrl.signupForm[field].$touched && ctrl.signupForm[field].$invalid;
        };

        var showMessages = function (field) {
            return ctrl.signupForm[field].$touched || ctrl.signupForm.$submitted
        };

        ctrl.showEmailPrompt = false;
        ctrl.showUsernamePrompt = false;
        ctrl.showCollegePrompt = false;
        ctrl.showSubmittedPrompt = false;
        ctrl.toggleEmailPrompt = toggleEmailPrompt;
        ctrl.toggleUsernamePrompt = toggleUsernamePrompt;
        ctrl.toggleCollegePrompt = toggleCollegePrompt;
        ctrl.getPasswordType = getPasswordType;
        ctrl.hasErrorClass = hasErrorClass;
        ctrl.showMessages = showMessages;
        ctrl.newCustomer = newCustomer;
        ctrl.signup = signup;
        ctrl.clearForm = clearForm;
    })
    .directive('validatePasswordCharacters', function () {
        return {
            require: 'ngModel',
            link: function ($scope, element, attrs, ngModel) {
                ngModel.$validators.lowerCase = function (value) {
                    var pattern = /[a-z]+/;
                    return (typeof value !== 'undefined') && pattern.test(value);
                };
                ngModel.$validators.upperCase = function (value) {
                    var pattern = /[A-Z]+/;
                    return (typeof value !== 'undefined') && pattern.test(value);
                };
                ngModel.$validators.number = function (value) {
                    var pattern = /\d+/;
                    return (typeof value !== 'undefined') && pattern.test(value);
                };
                ngModel.$validators.specialCharacter = function (value) {
                    var pattern = /\W+/;
                    return (typeof value !== 'undefined') && pattern.test(value);
                };
                ngModel.$validators.eightCharacters = function (value) {
                    return (typeof value !== 'undefined') && value.length >= 8;
                };
            }
        }
    })
;

However, On debugging, it doesnt budge ast this line. Whats is the error????

the ctrl.newCustomer is a valid object and I am able to get the strings from my HTML page.

NAME - text input COLL - text input EMAIL - email input

Validation is taken care of

4
  • 2
    Check your console for errors. If none, check the network tab for red lines that indicate errors. Commented Nov 17, 2015 at 19:08
  • Do what @OmriAharon said. If still no clues, please tell me if campusconnect and us11 are suposed to be variables. Commented Nov 17, 2015 at 19:10
  • No. campusconnect and us11 arent varables. $http is not defined is the error I am seeing.... Commented Nov 17, 2015 at 19:14
  • you should share your full code, but it sounds like you haven't delared $http as a dependency Commented Nov 17, 2015 at 19:18

1 Answer 1

1

You must inject the $http service:

angular.module('ngMailChimp', ['ngAria', 'ngMessages', 'ngAnimate'])
    .controller('SignUpController', function ($http) {
        ...

Please notice that this form is not safe for minimization, in that case you should use:

.controller('SignUpController', ['$http', function ($http) {
    // your code
}]);
Sign up to request clarification or add additional context in comments.

1 Comment

$http works with promises, you can use the then function to assign a success handler and an error handler, take a look here: docs.angularjs.org/api/ng/service/$http the first section shows an example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.