Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit e63221b

Browse files
topherfangiotinayuangao
authored andcommitted
docs(bottomsheet): Add notes about .catch() usage. (#10378)
Newer versions of Angular will throw a `Possibly unhandled rejection` exception if you show a bottom sheet without providing a `.catch()` clause to handle the rejection. Add notes to `$mdBottomSheet` documentation and demos to show proper usage.
1 parent 0e5b849 commit e63221b

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

src/components/bottomSheet/bottom-sheet.js

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,26 @@ function MdBottomSheetDirective($mdBottomSheet) {
5656
* app.controller('MyController', function($scope, $mdBottomSheet) {
5757
* $scope.openBottomSheet = function() {
5858
* $mdBottomSheet.show({
59-
* template: '<md-bottom-sheet>Hello!</md-bottom-sheet>'
59+
* template: '<md-bottom-sheet>' +
60+
* 'Hello! <md-button ng-click="closeBottomSheet()">Close</md-button>' +
61+
* '</md-bottom-sheet>'
62+
* })
63+
*
64+
* // Fires when the hide() method is used
65+
* .then(function() {
66+
* console.log('You clicked the button to close the bottom sheet!');
67+
* })
68+
*
69+
* // Fires when the cancel() method is used
70+
* .catch(function() {
71+
* console.log('You hit escape or clicked the backdrop to close.');
6072
* });
6173
* };
74+
*
75+
* $scope.closeBottomSheet = function($scope, $mdBottomSheet) {
76+
* $mdBottomSheet.hide();
77+
* }
78+
*
6279
* });
6380
* </hljs>
6481
*/
@@ -70,6 +87,14 @@ function MdBottomSheetDirective($mdBottomSheet) {
7087
* @description
7188
* Show a bottom sheet with the specified options.
7289
*
90+
* <em><b>Note:</b> You should <b>always</b> provide a `.catch()` method in case the user hits the
91+
* `esc` key or clicks the background to close. In this case, the `cancel()` method will
92+
* automatically be called on the bottom sheet which will `reject()` the promise. See the @usage
93+
* section above for an example.
94+
*
95+
* Newer versions of Angular will throw a `Possibly unhandled rejection` exception if you forget
96+
* this.</em>
97+
*
7398
* @param {object} options An options object, with the following properties:
7499
*
75100
* - `templateUrl` - `{string=}`: The url of an html template file that will
@@ -110,7 +135,10 @@ function MdBottomSheetDirective($mdBottomSheet) {
110135
*
111136
* @description
112137
* Hide the existing bottom sheet and resolve the promise returned from
113-
* `$mdBottomSheet.show()`. This call will close the most recently opened/current bottomsheet (if any).
138+
* `$mdBottomSheet.show()`. This call will close the most recently opened/current bottomsheet (if
139+
* any).
140+
*
141+
* <em><b>Note:</b> Use a `.then()` on your `.show()` to handle this callback.</em>
114142
*
115143
* @param {*=} response An argument for the resolved promise.
116144
*
@@ -124,6 +152,8 @@ function MdBottomSheetDirective($mdBottomSheet) {
124152
* Hide the existing bottom sheet and reject the promise returned from
125153
* `$mdBottomSheet.show()`.
126154
*
155+
* <em><b>Note:</b> Use a `.catch()` on your `.show()` to handle this callback.</em>
156+
*
127157
* @param {*=} response An argument for the rejected promise.
128158
*
129159
*/

src/components/bottomSheet/demoBasicUsage/script.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ angular.module('bottomSheetDemo1', ['ngMaterial'])
2222
controller: 'ListBottomSheetCtrl'
2323
}).then(function(clickedItem) {
2424
$scope.alert = clickedItem['name'] + ' clicked!';
25+
}).catch(function(error) {
26+
// User clicked outside or hit escape
2527
});
2628
};
2729

@@ -38,6 +40,8 @@ angular.module('bottomSheetDemo1', ['ngMaterial'])
3840
.position('top right')
3941
.hideDelay(1500)
4042
);
43+
}).catch(function(error) {
44+
// User clicked outside or hit escape
4145
});
4246
};
4347
})

0 commit comments

Comments
 (0)