In the Angular 4,
app.component.html
<div>Counter: {{GetCount()}}</div>
app.component.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
constructor() {
}
ngOnInit()
{
}
counter:number = 1;
GetCount(): any {
this.counter++;
return this.counter;
}
}
My output was on the screen:
Counter: 4
How it is possible? I am calling the GetCount method only once in my html and It's hitting 4 times when I put break point in the method. What I am doing wrong here.