angular -empty

时间:2016-06-15 13:53:03

标签: html angularjs twitter-bootstrap

我使用bootstrap警告框显示成功消息。提交警告框后,消息显示完美,但问题是,在提交空警报框之前。日Thnx。这是代码

$scope.resetPassword = function () {
        var data = {
            email: $scope.resetPasswordEmail
        };
        $http.post(serviceBase + 'aaaaaaaaaaaa', data).then(function (response) {
            $scope.successfullyReset = true;
            $scope.message = "Email has been send successfully, you will be redicted to login page in 5 seconds.";
            startTimer();
        }, function (response) {
            $scope.successfullyReset = false;
            $scope.message = "Failed to send mail. There is no user with requested email";

        });

    };

和html代码在这里

<div data-ng-hide="message == ''" data-ng-class="(successfullyReset) ? 'alert alert-success' : 'alert alert-danger'">
            {{message}}
        </div><br />

这里是图片,提交之前看起来如何 enter image description here

2 个答案:

答案 0 :(得分:3)

警告框永远不会被隐藏,因为您在回调中定义了变量message,您应该在控制器的开头定义它。

 $scope.message = '';

答案 1 :(得分:1)

首先在$scope.message;块之外声明$http

 $scope.resetPassword = function () {
    var data = {
        email: $scope.resetPasswordEmail
    };

    $scope.message;

    $http.post(serviceBase + 'aaaaaaaaaaaa', data).then(function (response) {
        $scope.successfullyReset = true;
        $scope.message = "Email has been send successfully, you will be redicted to login page in 5 seconds.";
        startTimer();
    }, function (response) {
        $scope.successfullyReset = false;
        $scope.message = "Failed to send mail. There is no user with requested email";

    });

};