# \[rc0\] Calling a custom component, variable is always undefined

**URL:** <https://forum.ionicframework.com/t/rc0-calling-a-custom-component-variable-is-always-undefined/65805>\
**Category:** ionic-v3\
**Created:** [October 4, 2016, 10:44pm UTC](https://forum.ionicframework.com/t/rc0-calling-a-custom-component-variable-is-always-undefined/65805 "2016-10-04T22:44:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![DeeM52](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/deem52/32/101606_2.png) [@DeeM52](https://forum.ionicframework.com/u/DeeM52)\
**Post date:** [October 4, 2016, 10:44pm UTC](https://forum.ionicframework.com/t/rc0-calling-a-custom-component-variable-is-always-undefined/65805/1 "2016-10-04T22:44:28Z")

</div>

I’ve updated my ionic app from beta 11 to rc0. I am trying to use a custom component that I’m calling from the home-page.html

`<slider-component [songs]="recentlyViewedSongs" [viewId]="RecentViewId" </slider-component>`

In the slider-component.ts, I have a console.log which remains always undefined

```
    export class SliderComponent {
        
        @Input() songs: any; 
        @Input() viewId: any = []; //stores id of songs to be shown
         
        constructor(
            public nav: NavController, 
        ) { 
            console.log("In the SliderComponent, this.songs", this.songs); //shows an empty array
        }

```

In my app.module.ts, I’m using @NgModule like this

```
    @NgModule({
      declarations: [
        MyApp,
        HomePage,
        SliderComponent
      ],
      imports: [
        IonicModule.forRoot(MyApp)
      ],
      bootstrap: [IonicApp],
      entryComponents: [
        MyApp,
        HomePage,
        SliderComponent
      ],
      providers: []
    })
    export class AppModule {}

```

Any ideas on what I’m doing wrong?

---

<div class="post-metadata">

**Author:** ![ecureuill](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/ecureuill/32/102618_2.png) [@ecureuill](https://forum.ionicframework.com/u/ecureuill)\
**Post date:** [October 4, 2016, 10:49pm UTC](https://forum.ionicframework.com/t/rc0-calling-a-custom-component-variable-is-always-undefined/65805/2 "2016-10-04T22:49:16Z")

</div>

Try put the `console.log` in `ngAfterViewInit` or `ionViewDidLoad`

**Note**  
The ionic lifecycle hooks is ionViewDidLocad, but since there is an issue with child contents, I’m avoiding it.

> <https://github.com/ionic-team/ionic/issues/8449>

---

<div class="post-metadata">

**Author:** ![DeeM52](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/deem52/32/101606_2.png) [@DeeM52](https://forum.ionicframework.com/u/DeeM52)\
**Post date:** [October 4, 2016, 11:24pm UTC](https://forum.ionicframework.com/t/rc0-calling-a-custom-component-variable-is-always-undefined/65805/3 "2016-10-04T23:24:33Z")

</div>

Thanks for the idea. I’ve used ngOnit and variable was defined.

I was not able to use the ionic lifecycle hooks. Do I need to import them? How to use them?

---

<div class="post-metadata">

**Author:** ![ecureuill](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/ecureuill/32/102618_2.png) [@ecureuill](https://forum.ionicframework.com/u/ecureuill)\
**Post date:** [October 4, 2016, 11:29pm UTC](https://forum.ionicframework.com/t/rc0-calling-a-custom-component-variable-is-always-undefined/65805/4 "2016-10-04T23:29:18Z")

</div>

No need for impot, see [doc](http://ionicframework.com/docs/v2/api/navigation/NavController/#lifecycle-events)

\*If you copy from my comment, it was misspelled, I already correct it

---

<div class="post-metadata">

**Author:** ![danilolr](https://avatars.discourse-cdn.com/v4/letter/d/278dde/32.png) [@danilolr](https://forum.ionicframework.com/u/danilolr)\
**Post date:** [October 4, 2016, 11:44pm UTC](https://forum.ionicframework.com/t/rc0-calling-a-custom-component-variable-is-always-undefined/65805/5 "2016-10-04T23:44:40Z")

</div>

@Input() songs: any = [];  
@Input() viewId: any;

---

<div class="post-metadata">

**Author:** ![DeeM52](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/deem52/32/101606_2.png) [@DeeM52](https://forum.ionicframework.com/u/DeeM52)\
**Post date:** [October 5, 2016, 4:07pm UTC](https://forum.ionicframework.com/t/rc0-calling-a-custom-component-variable-is-always-undefined/65805/6 "2016-10-05T16:07:35Z")

</div>

Thanks guys. Problem solved. One of the songs had an undefined variable and it was creating errors.

I’ve used used ionic lifecycle hook, ionViewDidLoad, but not showing anything. ngOnit is working fine.

> ionViewDidLoad() {  
> console.log(“In the SliderComponent ionViewDidLoad, this.songs”, this.songs);  
> }
