I googled several examples about using functions/variables from other components in Angular 4/5. They helped me a bit for understanding but I still couldn't figure out the solution to my problem.
I wanna call a standard JavaScript alert from another component.
I have a component, which has a variable like this:
center.ts
export class CenterPage {
public message = new alert("Warning");
center.html
<products [message]="message"></products>
I'm using @Input to get the message in products.ts
export class ProductsComponent {
@Input() message;
Now I want to show the alert, when the user clicks on a button in product.html
<button (click)="message"></button>
This seems to be wrong and I think this is not the right way how I'm trying to show the alert when the user clicks on the button.
How can I do this correctly?
EDIT
This is only one example. In the end I will have to call the same alert in several components. So I try to have only one function which I can call from all components so I won't have redundant code.
alert? Is that a class you created? Or are you trying to call a standard JavaScriptalert()function?