ionic-content-banner
ionic-content-banner copied to clipboard
TypeError: Cannot read property 'querySelector' of undefined
I have the ionic content banner in a side menu content view. And it throw error: TypeError: Cannot read property 'querySelector' of undefined
It regard to this line of code: getActiveView(body).querySelector('.scroll-content').appendChild(element[0]); line 149
What is going wrong? Could you fix that?
Thanks @hughred22 !! I'll try to check this out soon and if everything is good merge it in
Awesome!
Also encountered this.
FYI: This can also happen when you try to show a banner before the active view (ion-view[nav-view="active"]
) is in the DOM.
@davej What do you mean "before" the active view? You won't see it if you show it before the active view. The banner should show at the active view in order to be seen.
I have $ionicContentBanner.show()
in a controller but ion-view[nav-view="active"]
isn't created yet when $ionicContentBanner.show()
is called and I got the error described above. The error goes away if I put the call inside of a setTimeout
.
Instead of setTimeout, put your call in timeout() command. You need to wait till the ion-view is created before calling show(). timeout() with fix the digest circle for you and make sure show() is called last.
Yeah I understand the issue. I fire the function call on the $viewContentLoaded
event now so it's not an issue anymore. Perhaps the plugin could wait for the loaded event on the view too?
I have the same issue and even a timeout is not working for me. Any help?
+1
The same error. $timeout/setTimeout does not help. Any news on this issue @djett41 ?
Also for non-scrollable content areas:
getActiveView(body).querySelector('.scroll-content-false').appendChild(element[0]); getActiveView(body).querySelector('.scroll-content').appendChild(element[0]);
$timeout( ..., 200) helped me.
I had to set timeout to be 1000 to fix the problem. It's better to wait until your view becomes fully active to call show();