TypeError:content is undefined in ParallaxHeader.prototype.ngOnInit()


#1

Hey,I am new to ionic framework.I want to create a parallax effect on my page i have done all possible things to clear the error but i can’t able to clear this error.Help me out from this run time error

my code is

import { Directive } from '@angular/core';
import { ElementRef, Renderer,Component, OnInit} from '@angular/core';
export class ParallaxHeader {    
header  : any;  
headerHeight: any;  
translateAmt: any;   
 scaleAmt : any;    
content: any; 
 constructor(public element: ElementRef,public renderer: Renderer) {    
 this.ngOnInit(this.content);
  }
  ngOnInit(content){      
  content = this.element.nativeElement.getElementsByClassName('scroll-content')[0];        
this.header = content.getElementsByClassName('header-image')[0];        let mainContent = content.getElementsByClassName('main-content')[0];      
   this.headerHeight = this.header.clientHeight;       
  this.renderer.setElementStyle(this.header, 'webkitTransformOrigin', 'center bottom');        this.renderer.setElementStyle(this.header, 'background-size', 'cover');        this.renderer.setElementStyle(mainContent, 'position', 'absolute');  
}


#2

ngOnInit is a lifecycle method that is called automatically when init is done. You don’t have to call is yourself. It also doesn’t take any variable I think.


#3

thanks…it worked bro.:slight_smile: