ng-click不会使用mdDialog第二次触发

时间:2017-03-30 17:38:55

标签: angularjs angularjs-ng-click mddialog

我是角度JS的新手。我正在尝试创建一个简单的mdDialog,其中包含一个用于注册的表单。 我第一次工作,但ng-click第二次没有响应。我在控制台中没有任何错误。 它适用于页面重新加载。

HTML

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

控制器

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;
        }
    });
}

模板:

<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>

0 个答案:

没有答案