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

Commit 2458c28

Browse files
committed
feat(alert): remove replace: true usage
- Remove `replace: true` usage BREAKING CHANGE: This removes the `replace: true` usage, so this has an effect on how one uses the directive in the template - see documentation for reference Closes #5986
1 parent 3819bbe commit 2458c28

File tree

5 files changed

+27
-54
lines changed

5 files changed

+27
-54
lines changed

src/alert/alert.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
angular.module('ui.bootstrap.alert', [])
22

3-
.controller('UibAlertController', ['$scope', '$attrs', '$interpolate', '$timeout', function($scope, $attrs, $interpolate, $timeout) {
3+
.controller('UibAlertController', ['$scope', '$element', '$attrs', '$interpolate', '$timeout', function($scope, $element, $attrs, $interpolate, $timeout) {
44
$scope.closeable = !!$attrs.close;
5+
$element.addClass('alert');
6+
$attrs.$set('role', 'alert');
7+
if ($scope.closeable) {
8+
$element.addClass('alert-dismissible');
9+
}
510

611
var dismissOnTimeout = angular.isDefined($attrs.dismissOnTimeout) ?
712
$interpolate($attrs.dismissOnTimeout)($scope.$parent) : null;
@@ -17,13 +22,12 @@ angular.module('ui.bootstrap.alert', [])
1722
return {
1823
controller: 'UibAlertController',
1924
controllerAs: 'alert',
25+
restrict: 'A',
2026
templateUrl: function(element, attrs) {
2127
return attrs.templateUrl || 'uib/template/alert/alert.html';
2228
},
2329
transclude: true,
24-
replace: true,
2530
scope: {
26-
type: '@',
2731
close: '&'
2832
}
2933
};

src/alert/docs/demo.html

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
<div ng-controller="AlertDemoCtrl">
22
<script type="text/ng-template" id="alert.html">
3-
<div class="alert" style="background-color:#fa39c3;color:white" role="alert">
4-
<div ng-transclude></div>
5-
</div>
3+
<div ng-transclude></div>
64
</script>
75

8-
<uib-alert ng-repeat="alert in alerts" type="{{alert.type}}" close="closeAlert($index)">{{alert.msg}}</uib-alert>
9-
<uib-alert template-url="alert.html">A happy alert!</uib-alert>
6+
<div uib-alert ng-repeat="alert in alerts" ng-class="'alert-' + (alert.type || 'warning')" close="closeAlert($index)">{{alert.msg}}</div>
7+
<div uib-alert template-url="alert.html" style="background-color:#fa39c3;color:white">A happy alert!</div>
108
<button type="button" class='btn btn-default' ng-click="addAlert()">Add Alert</button>
119
</div>

src/alert/docs/readme.md

+2-6
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,11 @@ This directive can be used both to generate alerts from static and dynamic model
55
* `close()`
66
<small class="badge">$</small> -
77
A callback function that gets fired when an `alert` is closed. If the attribute exists, a close button is displayed as well.
8-
8+
99
* `dismiss-on-timeout`
1010
_(Default: `none`)_ -
1111
Takes the number of milliseconds that specify the timeout duration, after which the alert will be closed. This attribute requires the presence of the `close` attribute.
12-
12+
1313
* `template-url`
1414
_(Default: `uib/template/alert/alert.html`)_ -
1515
Add the ability to override the template used in the component.
16-
17-
* `type`
18-
_(Default: `warning`)_ -
19-
Defines the type of the alert. Go to [bootstrap page](http://getbootstrap.com/components/#alerts) to see the type of alerts available.

src/alert/test/alert.spec.js

+10-33
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ describe('uib-alert', function() {
1212

1313
element = angular.element(
1414
'<div>' +
15-
'<uib-alert ng-repeat="alert in alerts" type="{{alert.type}}"' +
15+
'<div uib-alert ng-repeat="alert in alerts" ' +
16+
'ng-class="\'alert-\' + (alert.type || \'warning\')" ' +
1617
'close="removeAlert($index)">{{alert.msg}}' +
17-
'</uib-alert>' +
18+
'</div>' +
1819
'</div>');
1920

2021
scope.alerts = [
@@ -41,7 +42,7 @@ describe('uib-alert', function() {
4142
it('should expose the controller to the view', function() {
4243
$templateCache.put('uib/template/alert/alert.html', '<div>{{alert.text}}</div>');
4344

44-
element = $compile('<uib-alert></uib-alert>')(scope);
45+
element = $compile('<div uib-alert></div>')(scope);
4546
scope.$digest();
4647

4748
var ctrl = element.controller('uib-alert');
@@ -50,40 +51,23 @@ describe('uib-alert', function() {
5051
ctrl.text = 'foo';
5152
scope.$digest();
5253

53-
expect(element.html()).toBe('foo');
54+
expect(element.html()).toBe('<div class="ng-binding">foo</div>');
5455
});
5556

5657
it('should support custom templates', function() {
5758
$templateCache.put('foo/bar.html', '<div>baz</div>');
5859

59-
element = $compile('<uib-alert template-url="foo/bar.html"></uib-alert>')(scope);
60+
element = $compile('<div uib-alert template-url="foo/bar.html"></div>')(scope);
6061
scope.$digest();
6162

62-
expect(element.html()).toBe('baz');
63+
expect(element.html()).toBe('<div>baz</div>');
6364
});
6465

6566
it('should generate alerts using ng-repeat', function() {
6667
var alerts = createAlerts();
6768
expect(alerts.length).toEqual(3);
6869
});
6970

70-
it('should use correct classes for different alert types', function() {
71-
var alerts = createAlerts();
72-
expect(alerts.eq(0)).toHaveClass('alert-success');
73-
expect(alerts.eq(1)).toHaveClass('alert-error');
74-
expect(alerts.eq(2)).toHaveClass('alert-warning');
75-
});
76-
77-
it('should respect alert type binding', function() {
78-
var alerts = createAlerts();
79-
expect(alerts.eq(0)).toHaveClass('alert-success');
80-
81-
scope.alerts[0].type = 'error';
82-
scope.$digest();
83-
84-
expect(alerts.eq(0)).toHaveClass('alert-error');
85-
});
86-
8771
it('should show the alert content', function() {
8872
var alerts = createAlerts();
8973

@@ -115,22 +99,15 @@ describe('uib-alert', function() {
11599
});
116100

117101
it('should not show close button and have the dismissible class if no close callback specified', function() {
118-
element = $compile('<uib-alert>No close</uib-alert>')(scope);
102+
element = $compile('<div uib-alert>No close</div>')(scope);
119103
scope.$digest();
120104
expect(findCloseButton(0)).toBeHidden();
121105
expect(element).not.toHaveClass('alert-dismissible');
122106
});
123107

124-
it('should be possible to add additional classes for alert', function() {
125-
var element = $compile('<uib-alert class="alert-block" type="info">Default alert!</uib-alert>')(scope);
126-
scope.$digest();
127-
expect(element).toHaveClass('alert-block');
128-
expect(element).toHaveClass('alert-info');
129-
});
130-
131108
it('should close automatically if dismiss-on-timeout is defined on the element', function() {
132109
scope.removeAlert = jasmine.createSpy();
133-
$compile('<uib-alert close="removeAlert()" dismiss-on-timeout="500">Default alert!</uib-alert>')(scope);
110+
$compile('<div uib-alert close="removeAlert()" dismiss-on-timeout="500">Default alert!</div>')(scope);
134111
scope.$digest();
135112

136113
$timeout.flush();
@@ -140,7 +117,7 @@ describe('uib-alert', function() {
140117
it('should not close immediately with a dynamic dismiss-on-timeout', function() {
141118
scope.removeAlert = jasmine.createSpy();
142119
scope.dismissTime = 500;
143-
$compile('<uib-alert close="removeAlert()" dismiss-on-timeout="{{dismissTime}}">Default alert!</uib-alert>')(scope);
120+
$compile('<div uib-alert close="removeAlert()" dismiss-on-timeout="{{dismissTime}}">Default alert!</div>')(scope);
144121
scope.$digest();
145122

146123
$timeout.flush(100);

template/alert/alert.html

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
<div class="alert" ng-class="['alert-' + (type || 'warning'), closeable ? 'alert-dismissible' : null]" role="alert">
2-
<button ng-show="closeable" type="button" class="close" ng-click="close({$event: $event})">
3-
<span aria-hidden="true">&times;</span>
4-
<span class="sr-only">Close</span>
5-
</button>
6-
<div ng-transclude></div>
7-
</div>
1+
<button ng-show="closeable" type="button" class="close" ng-click="close({$event: $event})">
2+
<span aria-hidden="true">&times;</span>
3+
<span class="sr-only">Close</span>
4+
</button>
5+
<div ng-transclude></div>

0 commit comments

Comments
 (0)