0

Following code is not working. It is supposed to show error or warning alert. Am I doing it correct?

<div ng-controller="HeaderController">
    <div ng-class='{alert-danger:show, warning:isWarning}' class="alert" ng-show="show">{{messageText}}</div>
    <button ng-click='showError()'>Simulate Error</button>
    <button ng-click='showWarning()'>Simulate Warning</button>
</div>

</div>

and

<script>

    var HeaderController = function ($scope) {
        $scope.isError = false;
        $scope.isWarning = false;
        $scope.show = false;

        $scope.showError = function () {
            $scope.messageText = 'This is an error!';
            $scope.isError = true;
            $scope.isWarning = false;
            $scope.show = true;
        };

    }
</script>
1

1 Answer 1

1

You should wrap the class, in ng-class with a single quotes:

<div ng-class="{'alert-danger':show, 'warning':isWarning}" class="alert" ng-show="show">{{messageText}}</div>

It was "documented" on a comment in the ng-class docs, but they removed the discuss from there.

Sign up to request clarification or add additional context in comments.

Comments

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.