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

Commit ca07b76

Browse files
crisbetoThomasBurleson
authored andcommitted
fix(sidenav): don't log an error when waiting for an instance.
* The `$mdSidenav` service was logging errors, even if the option to wait for an asynchronous instance was passed. This changes it to only log if the lookup for the instance is synchronous. * Fixes the error for an invalid sidenav instance name not being logged if the `enableWait` argument is passed. * Adds info about the async argument of `$mdSidenav` in the docs. Fixes #8308. Closes #8326
1 parent a3cd619 commit ca07b76

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

src/components/sidenav/sidenav.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,17 @@ angular
2323
*
2424
* @description
2525
* `$mdSidenav` makes it easy to interact with multiple sidenavs
26-
* in an app.
26+
* in an app. When looking up a sidenav instance, you can either look
27+
* it up synchronously or wait for it to be initializied asynchronously.
28+
* This is done by passing the second argument to `$mdSidenav`.
2729
*
2830
* @usage
2931
* <hljs lang="js">
3032
* // Async lookup for sidenav instance; will resolve when the instance is available
33+
* $mdSidenav(componentId, true).then(function(instance) {
34+
* $log.debug( componentId + "is now ready" );
35+
* });
36+
* // Sync lookup for sidenav instance; this will resolve immediately.
3137
* $mdSidenav(componentId).then(function(instance) {
3238
* $log.debug( componentId + "is now ready" );
3339
* });
@@ -75,8 +81,9 @@ function SidenavService($mdComponentRegistry, $mdUtil, $q, $log) {
7581
return function(handle, enableWait) {
7682
if ( angular.isUndefined(handle) ) return service;
7783

78-
var instance = service.find(handle);
79-
return !instance && (enableWait === true) ? service.waitFor(handle) :
84+
var shouldWait = enableWait === true;
85+
var instance = service.find(handle, shouldWait);
86+
return !instance && shouldWait ? service.waitFor(handle) :
8087
!instance && angular.isUndefined(enableWait) ? addLegacyAPI(service, handle) : instance;
8188
};
8289

@@ -106,9 +113,11 @@ function SidenavService($mdComponentRegistry, $mdUtil, $q, $log) {
106113
* Synchronously lookup the controller instance for the specified sidNav instance which has been
107114
* registered with the markup `md-component-id`
108115
*/
109-
function findInstance(handle) {
116+
function findInstance(handle, shouldWait) {
110117
var instance = $mdComponentRegistry.get(handle);
111-
if(!instance) {
118+
119+
if (!instance && !shouldWait) {
120+
112121
// Report missing instance
113122
$log.error( $mdUtil.supplant(errorMsg, [handle || ""]) );
114123

@@ -124,7 +133,7 @@ function SidenavService($mdComponentRegistry, $mdUtil, $q, $log) {
124133
* Deferred lookup of component instance using $component registry
125134
*/
126135
function waitForInstance(handle) {
127-
return $mdComponentRegistry.when(handle);
136+
return $mdComponentRegistry.when(handle).catch($log.error);
128137
}
129138
}
130139
/**
@@ -263,7 +272,7 @@ function SidenavDirective($mdMedia, $mdUtil, $mdConstant, $mdTheming, $animate,
263272
if (!angular.isDefined(attr.mdDisableBackdrop)) {
264273
backdrop = $mdUtil.createBackdrop(scope, "_md-sidenav-backdrop md-opaque ng-enter");
265274
}
266-
275+
267276
element.addClass('_md'); // private md component indicator for styling
268277
$mdTheming(element);
269278

@@ -277,7 +286,7 @@ function SidenavDirective($mdMedia, $mdUtil, $mdConstant, $mdTheming, $animate,
277286
});
278287

279288
scope.$on('$destroy', function(){
280-
backdrop && backdrop.remove()
289+
backdrop && backdrop.remove();
281290
});
282291

283292
scope.$watch(isLocked, updateIsLocked);

0 commit comments

Comments
 (0)