ItSolutionStuff.com

Angular 11/10 Call Component Function on Button Click Example

By Hardik Savani • October 20, 2023
Angular

In this quick example, let's see angular 10 button call component function. step by step explain angular 11/10 call component function on button click. if you have question about angular 10 click event example then i will give simple example with solution. you'll learn angular 10 click event example. you will do the following things for button click angular 10.

If you are new and very beginner with angular 10 application and if you are looking for simple example of button click event and call a component function then i will help you using bellow example.

In this example, we will create two functions, one is very simple and without any argument call clickFunction() and another we will call dynamic argument with jquery object call callFunction($event, post). one function will call alert and another will only print on console.

Preview:

aap.component.html

<div class="container">

<h1>Call a Function on click Event in Angular 10 - ItSolutionStuff.com</h1>

<button (click)="clickFunction()" class="btn btn-success">Click Me</button>

<ul class="list-group" *ngFor="let post of posts">

<li class="list-group-item" (click)="callFunction($event, post)">

{{ post.title }}

</li>

</ul>

</div>

you can install bootstrap for your application because i used it. you can install it by this link: Install Bootstrap to Angular 10.

aap.component.ts

import { Component } from '@angular/core';

@Component({

selector: 'app-root',

templateUrl: './app.component.html',

styleUrls: ['./app.component.css']

})

export class AppComponent {

title = 'appNgContent';

posts = [

{

id: 1,

title: 'Angular Http Post Request Example'

},

{

id: 2,

title: 'Angular 10 Routing and Nested Routing Tutorial With Example'

},

{

id: 3,

title: 'How to Create Custom Validators in Angular 10?'

},

{

id: 4,

title: 'How to Create New Component in Angular 10?'

}

];

callFunction(event, post){

console.log(post);

}

clickFunction() {

alert("clicked me!");

}

}

Output:

{id: 2, title: "Angular 10 Routing and Nested Routing Tutorial With Example"}

I hope it can help you...

Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

Angular 10 Install Font Awesome Icons Example

Read Now →

Angular 10 Custom Validator Tutorial Example

Read Now →

Angular 10 Template Driven Forms with Validation Example

Read Now →

Angular 11/10 Create Custom Pipe Example

Read Now →

Angular 10 Install Material Design Example

Read Now →

Angular 10 Create New Component using Command

Read Now →

Angular 10 Create New Project Example

Read Now →

How to Use Bootstrap 4 in Angular 10?

Read Now →

How to Upgrade Angular CLI to Angular 9 to Angular 10 Version?

Read Now →

Angular 10 Reactive Forms Validation Example

Read Now →

Angular Input Keydown Event Example

Read Now →