Hello Folks,
I am getting this error “Cannot read property ‘scrollToBottom’ of undefined” and haven’t got a solution to this anywhere, hence this post:
Here is my use case:
I have a custom accordion list, and on click of one of the list (since it will have some content) I want the user not to scroll to the bottom, hence using that property. I have only pasted the relevant code
This is my .ts
import { Component, ViewChild } from '@angular/core';
import { NavController,Platform, Content} from 'ionic-angular';
import { ToastController } from 'ionic-angular';
import { NativeStorage } from '@ionic-native/native-storage';
@Component({
selector: 'page-profile',
templateUrl: 'profile.html'
})
export class ProfilePage {
@ViewChild('content') content: any;
constructor(public navCtrl: NavController, private nativeStorage : NativeStorage, private toastCtrl : ToastController, platform : Platform ) {
// other methods
}
ionViewDidLoad()
{
this.IonAccordion()
}
IonAccordion(){
this.accElement = document.getElementsByClassName('ion-accordion-header');
var i;
for (i = 0; i < this.accElement.length; i++) {
console.log(i)
this.accElement[i].addEventListener("click", function()
{
this.classList.toggle("active");
console.log("click");
var panel = this.nextElementSibling;
if (panel.style.maxHeight){
console.log(panel.style.maxHeight);
panel.style.maxHeight = null;
} else {
panel.style.maxHeight = panel.scrollHeight + "px";
this.content.scrollToBottom(300);
}
});
}
}
}
This is my .html file,
<ion-content #content>
<ion-row>
<ion-col>
<div class="ion-accordion-header">Accordion 1 </div>
<div class="panel">
<p>Accordion content</p>
</div>
</ion-col>
</ion-row>
<ion-row>
<ion-col>
<div class="ion-accordion-header">Accordion 2 </div>
<div class="panel">
<p>Accordion content</p>
</div>
</ion-col>
</ion-row>
</ion-content>
Version info
cli packages: (F:\classette\node_modules)
@ionic/cli-plugin-cordova : 1.6.2 @ionic/cli-plugin-ionic-angular : 1.4.1 @ionic/cli-utils : 1.7.0 ionic (Ionic CLI) : 3.7.0
global packages:
Cordova CLI : 7.0.1
local packages:
@ionic/app-scripts : 1.3.7 Cordova Platforms : android 6.2.3 Ionic Framework : ionic-angular 3.3.0
System:
Node : v6.10.2 OS : Windows 10 npm : 3.10.10