Uncaught TypeError: Cannot read property 'resize' of undefined

I’ve got three sections on my page, which is open and close by the click, but the issue is when i’m opening all sections it does not fit on the page, i’m trying to write click event which will $ionicScrollDelegate.resize() this sections, here is how i’m doing this:

var toggleButtons = document.querySelectorAll(‘button.toggle-button’);

for (var i = 0; i < toggleButtons.length; i++) {
  toggleButtons[i].addEventListener('click', function() {
    $ionicScrollDelegate.resize();
  }, false)
}

But every time i’m clicking on one of this button, i’m getting this error, why?

Where is located that source code you put here? Is it in a controller?
You probably forgot to inject $ionicScrollDelegate.

Also, you should take time to learn AngularJS, your code looks very JQuery-ish, doing the same in idiomatic Angular would be much more elegant and easier.