$mdSidenav throws error condition
In my .run function of the application I have a listener for locationChangeStart as follows:
$rootScope.$on("$locationChangeStart",function(event, next, current){
$mdSidenav('left_panel').close();
});
On starting the application the left_panel has not been initialized yet and the error "No instance found for handle left_panel" is raised.
Recommendation: If the panel is not initialized $mdSidenav should exit the function.
Does the sidenav have a component id of left_panel? You can use this attribute: md-component-id="left_panel"
It does. The run block is running first and therefore the $mdSidenav object left-panel has not been initialized as the html is loaded after the location has changed.
References #1311
Closing as a duplicate of #1311.
@kschwidder Have you solved the problem? I still have the problem after applying #1311. Just like you case, in my .run function, I use
$rootScope.$on("$locationChangeStart", function(event, next, current){
$mdSidenav("left").then(function(left){ left.close();});
});
and md-sidenav directive in a template file(loaded by ng-include)
<md-sidenav class="md-sidenav-left md-whiteframe-z2" md-component-id="left" md-is-open="isSidenavOn" md-swipe-left="toggleSidenav('close')">
...
</md-sidenav>
I am having the same issue using UI-Router. I use $viewContentLoaded in my my run function to close a sidebar after navigation.
The first time the event fires, there are no instances registered in the function ComponentRegistry of the angular-material.js of the module material.core.componentRegistry.
Second time it is triggers (gets triggered 3 times on page reload in my app) it does have instances registered and the lookup goes fine.
I must tell you that I am having a 2 view system (code in Coffee):
$stateProvider
# abstract views / layout
.state 'private',
url: ''
abstract: true
views:
'app':
templateUrl: 'client/views/layouts/privateLayout.html'
.state 'public',
url: ''
abstract: true
views:
'app':
templateUrl: 'client/views/layouts/publicLayout.html'
# start private routes
.state 'private.home',
url: '/'
views:
"container@private":
templateUrl: 'client/views/home/home.html'
So when the route private.home is loaded, the event viewContentLoaded fires 3 times. First to load the master index file I guess and then when it renders the privateGlobalLayout (which has the sidebar) and then the inner view which. When loading the index file
head
meta(name="viewport" content="width=device-width, initial-scale=1")
base(href="/")
body(layout="column")
div(ui-view="app" layout="column" flex)
which doesn' thave any instance registered, it throws an error.
The private Global Layout
div(layout="column" flex)
div(ng-controller="AppCtrl" layout="row" flex)
md-sidenav.md-sidenav-left.md-whiteframe-z2(md-component-id='left' md-is-locked-open="$mdMedia('gt-md')" md-swipe-left="close('left')")
md-toolbar(layout="row" layout-align="center center")
etc....
So maybe my code is wrong, because it tries to get the sidebar instance when there is no registration of it on the first event fire. The second fire will find an instance registered. So I might have to look in my router to prevent it to try to look up the side bar on the first fire
@kwela Check solution here: https://github.com/SebastianMetzger/angular-material-inbox/issues/1
It works for now, using promise on mdComponentRegistry!