I currently have a interface set up for employees that looks like this:
export interface IEmployee {
name: string;
id: number;
annualSalary: number;
calculateMonthlySalary(annualSalary: number): number;
}
Now, I have a component that is implementing 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;
}
}
While trying to compute the monthly salary using the calculateMonthlySalary
method from the interface and displaying it in the view using *ngFor
, I encountered the following error:
ERROR ReferenceError: annualSalary is not defined
Please help correct me where I might be going wrong