-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Async lookup for sidenav instance logs an error in the console (when it should just wait until the instance is available). #8308
Comments
BTW, the documentation is buggy as it should mention the boolean argument (true): The workaround I found to avoid the log.error is to use [the undocumented] $mdComponentRegistry as follows: $mdComponentRegistry.when('left').then(function() {
// Now you can use $mdSidenav('left') or $mdSidenav('left', true) without getting an error.
$mdSidenav('left').toggle();
}) |
This happens because firing the |
I initially tried $timeout, but a low timeout (say even 200 milliseconds) wasn't enough to solve it --- maybe my macbook pro is slow :D Then I found a better workaround using: I believe this is what material should do: return function(handle, enableWait) {
Simple :) |
Yeah, passing in |
The current code doesn't do the same because it first tries to find the instance (which logs an error). Again, I believe the fix is a one line change: Current code:
}; New code: return function(handle, enableWait) { |
* 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 angular#8308.
* 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 angular#8308.
I have the same issue, with the workarround of @yoav-zibin the sidernav works well, but in my case if you navigate to another route and go back the sidernav stop working without any warning or error log, I fixed that destroying the sidernav on scope destroy event. It's strange, but I really don't sure why this works. var sidenavPromise = $mdComponentRegistry.when('sidenav');
var sidenavInstance;
sidenavPromise.then(function() {
if(sidenavInstance){
sidenavInstance.destroy();
}
sidenavInstance= $mdSidenav("sidenav");
$scope.$on("$destroy", sidenavInstance.destroy);
//Sidenav logic
}); |
From the docs:
https://material.angularjs.org/latest/api/service/$mdSidenav
// Async lookup for sidenav instance; will resolve when the instance is available
$mdSidenav(componentId).then(function(instance) {
$log.debug( componentId + "is now ready" );
});
However, when I do that, I get an error in the logs:
Even when passing true, it still logs the error:
$mdSidenav('left', true);
Except the error logs, things work correctly: the promise is resolved correctly :)
The problem is that it spams the error logs (and i have protractor tests that make sure the error log is empty).
The problem is in this code:
See:
The text was updated successfully, but these errors were encountered: