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

Commit c2645f4

Browse files
fix(alert): don't show close button if no close callback specified
1 parent 556a37e commit c2645f4

File tree

5 files changed

+33
-19
lines changed

5 files changed

+33
-19
lines changed

src/alert/alert.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ angular.module("ui.bootstrap.alert", []).directive('alert', function () {
44
templateUrl:'template/alert/alert.html',
55
transclude:true,
66
replace:true,
7-
scope:{
8-
type:'=',
9-
close:'&'
7+
scope: {
8+
type: '=',
9+
close: '&'
10+
},
11+
link: function(scope, iElement, iAttrs, controller) {
12+
scope.closeable = "close" in iAttrs;
1013
}
1114
};
12-
});
15+
});

src/alert/docs/demo.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<div ng-controller="AlertDemoCtrl">
22
<alert ng-repeat="alert in alerts" type="alert.type" close="closeAlert($index)">{{alert.msg}}</alert>
33
<button class='btn' ng-click="addAlert()">Add Alert</button>
4-
</div>
4+
</div>

src/alert/docs/readme.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
Alert is an AngularJS-version of bootstrap's alert.
22

3-
This directive can be used to generate alerts from the dynamic model data (using the ng-repeat directive);
3+
This directive can be used to generate alerts from the dynamic model data (using the ng-repeat directive);
4+
5+
The presence of the "close" attribute determines if a close button is displayed

src/alert/test/alert.spec.js

+20-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
describe("alert", function () {
2+
23
var scope, ctrl, model, $compile;
34
var element;
45

@@ -11,14 +12,16 @@ describe("alert", function () {
1112
$compile = _$compile_;
1213

1314
element = angular.element(
14-
"<div><alert ng-repeat='alert in alerts' type='alert.type'" +
15-
"close='removeAlert($index)'>{{alert.msg}}" +
16-
"</alert></div>");
15+
"<div>" +
16+
"<alert ng-repeat='alert in alerts' type='alert.type'" +
17+
"close='removeAlert($index)'>{{alert.msg}}" +
18+
"</alert>" +
19+
"</div>");
1720

1821
scope.alerts = [
1922
{ msg:'foo', type:'success'},
2023
{ msg:'bar', type:'error'},
21-
{ msg:'baz' }
24+
{ msg:'baz'}
2225
];
2326
}));
2427

@@ -48,13 +51,6 @@ describe("alert", function () {
4851
expect(alerts.eq(2)).not.toHaveClass('alert-block');
4952
});
5053

51-
it('it should be possible to add additional classes for alert', function () {
52-
var element = $compile('<alert class="alert-block" type="\'info\'">Default alert!</alert>')(scope);
53-
scope.$digest();
54-
expect(element).toHaveClass('alert-block');
55-
expect(element).toHaveClass('alert-info');
56-
});
57-
5854
it("should fire callback when closed", function () {
5955

6056
var alerts = createAlerts();
@@ -67,4 +63,17 @@ describe("alert", function () {
6763
expect(scope.removeAlert).toHaveBeenCalledWith(1);
6864
});
6965

66+
it('should not show close buttons if no close callback specified', function () {
67+
var element = $compile('<alert>No close</alert>')(scope);
68+
scope.$digest();
69+
expect(findCloseButton(0).length).toEqual(0);
70+
});
71+
72+
it('it should be possible to add additional classes for alert', function () {
73+
var element = $compile('<alert class="alert-block" type="\'info\'">Default alert!</alert>')(scope);
74+
scope.$digest();
75+
expect(element).toHaveClass('alert-block');
76+
expect(element).toHaveClass('alert-info');
77+
});
78+
7079
});

template/alert/alert.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<div class='alert' ng-class='type && "alert-" + type'>
2-
<button type='button' class='close' ng-click='close()'>&times;</button>
2+
<button ng-show='closeable' type='button' class='close' ng-click='close()'>&times;</button>
33
<div ng-transclude></div>
4-
</div>
4+
</div>

0 commit comments

Comments
 (0)