Home > Software design >  How to know a link is opened by clicking a button from outside in angular
How to know a link is opened by clicking a button from outside in angular

Time:05-23

I have UI link,if some one click that link through a button from another page,Angular UI need to know link is clicked through the button

CodePudding user response:

One possible solution:

Create a service ButtonState


export service ButtonState() {
public buttonClicked = false;

getButtonClicked() {
  return buttonClicked;
}

setButtonClicked() {

   this.buttonClicked = true;
}

resetButtonState() {
   this.buttonClicked = false;
}

}

In your html where you click the button

<button (click)="clickBtn()">Click</button>

In the component where button is present

clickBtn() { 
this.buttonStateService.setButtonClicked();

// Code for route navigate

}

In your Navigated Component.ts


ngOnInit() {
const isButtonClicked = this.buttonStateService.getButtonClicked;

}

CodePudding user response:

this button is in different website.

  • Related