Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 71531

Finally made a breakthrough passing data to a component - felt I should share

$
0
0

First I would like to say how I appreciate this forum, and the support crew who are so helpful in answering so many small questions. I tend not to write much - but I spent many hours on so many days searching for the answer to the many questions that naturally arise while programming.

I am a long time programmer - started back in 1974! - but I only started programming ionic/angular four months ago - so I consider myself a skilled newbie. I’m working on a project, and mostly have made good progress, but I find programming in Ionic/Angular very frustrating! The main frustration seems to come from things that an instructor in a course says will work not working. An example of that is the topic of this post “Passing data to a component via html”

I needed to figure this out - and several months ago I spent more than a week trying everything, without success. I finally figured out how to use a service as an exchange - so a component could “ask” what data it was to use by calling the service which the parent had nicely loaded up with data. I consider this a kludge.

Today, finally! I figured out a method that worked - which is what I felt I should share.

In html I had tried to pass data to the child using [myID]=“item.id.”

Then, as everyone said to do - I used @Input(‘myID’) to bind a component variable to that ID.

I only saw the ID as “undefined” which made me crazy.

Then, today, I saw someone in a forum (stack overflow…) make a slight comment:

“use ngAfterContentInit to get the data - not ngOnInit”

This was what I needed to see - the data is undefined in ngOnInit - but is valid in ngAfterContentInit!

So frustrating that I spent weeks struggling with this - finally writing a kludge work around - but now it works, thanks to some wise soul writing in a random post in a random forum.

Just thought I would share.

thanks for your time - and thanks to all those who are so helpful to all who struggle.

2 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 71531

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>