Wondering about the connection between salary.service
and player.component
in Angular 2. If the salary variable is updated in the service, will it automatically reflect in the view of the player component?
Initially, the player.component view displays a salary of 50000, showing that they are linked. However, I'm struggling to figure out how to update the value.
salary.service
export class SalaryService {
public salary = 50000; // starting value to be subtracted from
constructor() { }
public setSalary = (value) => { this.salary = this.salary - value };
}
player.component
export class PlayerComponent {
constructor(private salaryService:SalaryService) {}
public salary = this.salaryService.salary;
public updateSalary = (value) => { this.salaryService.setSalary(value) };
}
UPDATE
Resolved the issue by checking out the Plunker: