1

In my Component class (HeaderComponent), I want to access the changeBtnColorBg function everytime I click the two functions changeBannerArrow() and changeBannerImg()

Those functions are triggered on the onclick event in the HTML side

export class HeaderComponent implements OnInit {
    imgTotal = 3;
    currentImg = 0;

    imgHdr = [];

    changeBannerImg(imgSelect){
        /* some code here */
        changeBtnColorBg(this.currentImg, imgSelect);
    }


    changeBannerArrow(imgSelect){
        from = this.currentImg;

        /* some code here*/
        to = this.currentImg;

        changeBtnColorBg(from, to);

    }

    changeBtnColorBg(from, to){
        this.imgHdr[from].selected = false; //change back to transparent

        this.imgHdr[to].selected = true; //change bg color
    }
}

But this structure produces an error of

HeaderComponent.html:15 ERROR ReferenceError: changeBtnColorBg is not defined

Can someone please help? I'm new to this

1
  • wow, Angular 7 requires no TypeScript? Commented Oct 25, 2018 at 10:16

3 Answers 3

1

Seems you missed the this in your changeBannerArrow and changeBannerImg methods

  changeBannerArrow(imgSelect){
        from = this.currentImg;

        /* some code here*/
        to = this.currentImg;

        this.changeBtnColorBg(from, to);
}


   changeBannerImg(imgSelect){
        /* some code here */
        this.changeBtnColorBg(this.currentImg, imgSelect);
    }
Sign up to request clarification or add additional context in comments.

1 Comment

Hello! Thanks for this! I figured it out a couple of seconds ago that the command line also displays an error (new to this) Thanks for this!
1
changeBtnColorBg(this.currentImg, imgSelect);

to

this.changeBtnColorBg(this.currentImg, imgSelect); // add 'this'

Comments

0

try and Make the following changes :

export class HeaderComponent implements OnInit {
imgTotal = 3;
currentImg = 0;

imgHdr = [];

changeBannerImg(imgSelect){
    /* some code here */
    this.changeBtnColorBg(this.currentImg, imgSelect); // make change here
}


changeBannerArrow(imgSelect){
    from = this.currentImg;

    /* some code here*/
    to = this.currentImg;

    this.changeBtnColorBg(from, to); // make change here

}

changeBtnColorBg(from, to){
    this.imgHdr[from].selected = false; //change back to transparent

    this.imgHdr[to].selected = true; //change bg color
}

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.