ionic-content-banner icon indicating copy to clipboard operation
ionic-content-banner copied to clipboard

TypeError: Cannot read property 'querySelector' of undefined

Open hughred22 opened this issue 9 years ago • 14 comments

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?

hughred22 avatar Aug 25 '15 00:08 hughred22

Thanks @hughred22 !! I'll try to check this out soon and if everything is good merge it in

djett41 avatar Aug 25 '15 16:08 djett41

Awesome!

hughred22 avatar Aug 25 '15 22:08 hughred22

Also encountered this.

davej avatar Aug 27 '15 15:08 davej

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 avatar Aug 27 '15 15:08 davej

@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.

hughred22 avatar Aug 27 '15 16:08 hughred22

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.

davej avatar Aug 27 '15 17:08 davej

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.

hughred22 avatar Aug 27 '15 20:08 hughred22

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?

davej avatar Aug 27 '15 21:08 davej

I have the same issue and even a timeout is not working for me. Any help?

eusthace811 avatar Sep 23 '15 03:09 eusthace811

+1

MrPro100 avatar Sep 26 '15 10:09 MrPro100

The same error. $timeout/setTimeout does not help. Any news on this issue @djett41 ?

maks-rafalko avatar Sep 29 '15 21:09 maks-rafalko

Also for non-scrollable content areas:

getActiveView(body).querySelector('.scroll-content-false').appendChild(element[0]); getActiveView(body).querySelector('.scroll-content').appendChild(element[0]);

doorty avatar Feb 18 '16 13:02 doorty

$timeout( ..., 200) helped me.

DenniLa2 avatar Apr 08 '16 17:04 DenniLa2

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();

aubrey-fowler avatar Sep 06 '17 15:09 aubrey-fowler