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

Commit

Permalink
fix(sidenav): don't log an error when waiting for an instance.
Browse files Browse the repository at this point in the history
* The `$mdSidenav` service was throwing 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.
  • Loading branch information
crisbeto committed May 3, 2016
1 parent ce006cf commit c6bb6a7
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/components/sidenav/sidenav.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,17 @@ angular
*
* @description
* `$mdSidenav` makes it easy to interact with multiple sidenavs
* in an app.
* in an app. When looking up a sidenav instance, you can either look
* it up synchronously or wait for it to be initializied asynchronously.
* This is done by passing the second argument to `$mdSidenav`.
*
* @usage
* <hljs lang="js">
* // Async lookup for sidenav instance; will resolve when the instance is available
* $mdSidenav(componentId, true).then(function(instance) {
* $log.debug( componentId + "is now ready" );
* });
* // Sync lookup for sidenav instance; this will resolve immediately.
* $mdSidenav(componentId).then(function(instance) {
* $log.debug( componentId + "is now ready" );
* });
Expand Down Expand Up @@ -75,8 +81,9 @@ function SidenavService($mdComponentRegistry, $mdUtil, $q, $log) {
return function(handle, enableWait) {
if ( angular.isUndefined(handle) ) return service;

var instance = service.find(handle);
return !instance && (enableWait === true) ? service.waitFor(handle) :
var shouldWait = enableWait === true;
var instance = service.find(handle, shouldWait);
return !instance && shouldWait ? service.waitFor(handle) :
!instance && angular.isUndefined(enableWait) ? addLegacyAPI(service, handle) : instance;
};

Expand Down Expand Up @@ -106,9 +113,11 @@ function SidenavService($mdComponentRegistry, $mdUtil, $q, $log) {
* Synchronously lookup the controller instance for the specified sidNav instance which has been
* registered with the markup `md-component-id`
*/
function findInstance(handle) {
function findInstance(handle, shouldWait) {
var instance = $mdComponentRegistry.get(handle);
if(!instance) {

if(!instance && !shouldWait) {

// Report missing instance
$log.error( $mdUtil.supplant(errorMsg, [handle || ""]) );

Expand All @@ -124,7 +133,7 @@ function SidenavService($mdComponentRegistry, $mdUtil, $q, $log) {
* Deferred lookup of component instance using $component registry
*/
function waitForInstance(handle) {
return $mdComponentRegistry.when(handle);
return $mdComponentRegistry.when(handle).catch($log.error);
}
}
/**
Expand Down Expand Up @@ -263,7 +272,7 @@ function SidenavDirective($mdMedia, $mdUtil, $mdConstant, $mdTheming, $animate,
if (!angular.isDefined(attr.mdDisableBackdrop)) {
backdrop = $mdUtil.createBackdrop(scope, "_md-sidenav-backdrop md-opaque ng-enter");
}

element.addClass('_md'); // private md component indicator for styling
$mdTheming(element);

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

scope.$on('$destroy', function(){
backdrop && backdrop.remove()
backdrop && backdrop.remove();
});

scope.$watch(isLocked, updateIsLocked);
Expand Down

0 comments on commit c6bb6a7

Please sign in to comment.