I have an interface for employee as shown below
export interface IEmployee {
name: string;
id: number;
annualSalary: number;
calculateMonthlySalary(annualSalary: number): number;
}
component that implements the above interface
import { Component, OnInit } from '@angular/core';
import { IEmployee } from './../employee';
@Component({
selector: 'app-main',
templateUrl: './main.component.html',
styleUrls: ['./main.component.css']
})
export class MainComponent implements OnInit, IEmployee {
employees: IEmployee[];
constructor() {
this.employees = [
{name: 'john', id: 1, annualSalary: 90000, calculateMonthlySalary: this.calculateMonthlySalary(annualSalary) }
];
}
calculateMonthlySalary(annualSalary: number): any {
return annualSalary / 12;
}
}
Here, i'm trying to compute the monthly salary by using the interface calculateMonthlySalary
method and trying to display in view using *ngFor
but getting below error
ERROR ReferenceError: annualSalary is not defined
Please Correct me where i'm doing wrong