I am facing an issue with the interaction between my EmployeeService
and EmployeeController
. The service contains a specific object which I bind to the controller's scope:
app.controller('EmployeeController', function($scope, EmployeeService) {
$scope.employee = EmployeeService.getEmployee();
}
Within the HTML template, I display the name of the employee like this:
{{employee.name}}
When I make changes to the employee object in the EmployeeService
, such as updating the name, the template reflects the new name. However, if I completely replace the employee object using
EmployeeService.setEmployee({name: 'new name'})
, the template does not update accordingly.
This discrepancy is demonstrated in my Plunk here: http://plnkr.co/edit/k7oKd1VgsBvMGvVdP5kM?p=preview
In the provided Plunk, the functionality works for Employee Controller/Service but not for Manager Controller/Service. Any insights or help on this matter would be greatly appreciated.