繁体   English   中英

AngularJS ng-show仅触发一次

[英]AngularJS ng-show only triggering once

我有以下HTML

    <div class="alert alert-danger col-sm-10 col-sm-offset-1" ng-show="showErrorMessage">
        <button data-dismiss="alert" class="close" ng-click="closeErrorMessage()">
            ×
        </button>
        <i class="fa fa-check-circle"></i>
        <strong>Error</strong> The following errors have occurred:
        <div ng-repeat="error in createResp.Errors">{{error}}</div>
    </div>

在我的JavaScript中包含以下内容

   $scope.showErrorMessage = false;

   $scope.search = function () {
        var createOrderResp = myData.create($scope.request);

        createOrderResp.$promise.then(function (r) {
            $scope.createResp = r;
            if ($scope.createResp.Errors.length > 0) {
                $scope.showErrorMessage = true;
            }
        }, function (r) {
            handleResourceError(r);
        });
    };

    $scope.closeErrorMessage = function () {
        $scope.showErrorMessage = false;
    };

因此,从头到尾一切都很棒。 如果响应包含错误,则显示div。 但是,在单击关闭按钮closeErrorMessage()然后再次执行它之后,即使showErrorMessage标志变为true,也不会显示错误警报。

问题在于data-dismiss 它将删除整个alert块。 因此,使用范围内的变量触发ng-show将无济于事,因为将没有html部分,因此需要进行触发。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM