Call a function on click event in Angular 2

后端 未结 5 1587
难免孤独
难免孤独 2020-12-01 03:53

How to declare a function inside a component (typescript) and call it on a click event in Angular 2? Following is the code for the same functionality in Angular 1 for which

5条回答
  •  时光说笑
    2020-12-01 04:44

    Exact transfer to Angular2+ is as below:

    
    

    also in your component file:

    import { Component, OnInit } from "@angular/core";
    
    @Component({
      templateUrl:"button.html" //this is the component which has the above button html
    })
    
    export class App implements OnInit{
      constructor(){}
    
      ngOnInit(){
    
      }
    
      myFunc(){
        console.log("function called");
      }
    }
    

提交回复
热议问题