Passing data in Angular within same component

When I click on the button that calls the following method I get the selected package name logged out in the console, GREAT!

showPackageProducts(thispackage: Package): void {
    this.selectedPackageId =;
    this.selectedPackage = thispackage;
    this.productNames = this.selectedPackage.products.split(',');
    this.packageSelected = true;
    console.log('the package name is: ',;

when I try to output this in my html page (OUTSIDE OF MY LOOP) I get the last packagename displayed from my data

Please help?!

Sounds like you’re running into issues with this binding. this can be a bit confusing in JavaScript, an it’s worth looking into more deeply.

Adding to Ariel’s answer, after checking out the details about this check your html code again.
Html templates should not really have “this” keyword binding for their component properties. You should be fine interpolating the property without the “this” keyword.

Good Luck!

1 Like

if you are trying to run loop in HTML page you need to save data in **Array-like

showPackageProducts(thispackage: Package): void {
var package={};
    package.selectedPackageId =;

* List item

package.selectedPackage = thispackage;
    package.productNames = this.selectedPackage.products.split(',');
    package.packageSelected = true;
// you need to push the packge object to global variable
    console.log('the package name is: ',;

you can get all packages in html loop