Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

fix(alert): correct binding of alert type class #2146

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/alert/test/alert.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ describe('alert', function () {
expect(alerts.eq(2)).toHaveClass('alert-warning');
});

it('should respect alert type binding', function () {
var alerts = createAlerts();
expect(alerts.eq(0)).toHaveClass('alert-success');

scope.alerts[0].type = 'error';
scope.$digest();

expect(alerts.eq(0)).toHaveClass('alert-error');
});

it('should show the alert content', function() {
var alerts = createAlerts();

Expand Down
2 changes: 1 addition & 1 deletion template/alert/alert.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="alert" ng-class="{'alert-{{type || 'warning'}}': true, 'alert-dismissable': closeable}" role="alert">
<div class="alert" ng-class="'alert-' + (type || 'warning') + (closeable ? ' alert-dismissable' : '')" role="alert">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chrisirhc It would be more readable to use the array syntax, like this:

ng-class="['alert-' + (type || 'warning'), closeable ? 'alert-dismissable' : null]"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed, provided that it works :-)

<button ng-show="closeable" type="button" class="close" ng-click="close()">
<span aria-hidden="true">&times;</span>
<span class="sr-only">Close</span>
Expand Down