2

I'm new to angular JS. I'm trying to create a simple mdDialog which contains a form for signing up. I works the first time but the ng-click does not respond the second time. I don't get any errors in console. It works on page reload again.

HTML

<div ng-controller="UsersController as uc">
    <a ng-click="uc.signUp()">Click here to sign up for the newsletter!</a>
</div>

Controller

function subscribe() {
    var successHandler = function () {
        $mdDialog.show(
            $mdDialog.alert()
                .title('Subscription processed')
                .textContent('Thank you for signing up')
                .ok('Ok')
        );
    };

    if (self.email) {
        UsersService.subscribe(self.email, self.firstName, self.lastName).then(successHandler, errorHandler);
        self.email = '';
        self.firstName = '';
        self.lastName = '';
        $timeout(function () {
            self.showSubscribe = false;
        });
    }
}

function signUp() {
    $mdDialog.show({
        clickOutsideToClose: true,
        scope: $scope,
        templateUrl: '/view/templates/subscribe.html',
        controller: function DialogController($scope, $mdDialog) {
            $scope.cancel = $mdDialog.cancel;
        }
    });
}

Template:

<div class="newsletter" layout="row" layout-align="center start" flex>

<form  class="form" name="newsletterForm" ng-submit="uc.subscribe();">
    <div>... </div>
</form>
<div class="toolbar" flex-auto="10">
        <md-button class="md-icon-button" ng-click="cancel()">
            <md-icon aria-label="Close">clear</md-icon>
        </md-button>
</div>

nash63
  • 59
  • 1
  • 12
  • Well based on what you have above something is amiss. Your mdDialog is setting an inline controller yet the template is referencing uc.subscribe() which appears to be in UserController. That aside, at what point does it not respond? Have closed the dialog? Submitted the dialog? The dialog is still active? – Scott Mar 30 '17 at 17:56
  • It works on the first ng-click. I can submit the form. When i close the dialog and click on the link again the dialog does not open. – nash63 Mar 30 '17 at 18:10

0 Answers0