Hey, I'm having some trouble with this issue. I've searched everywhere for a solution, but couldn't find one, despite there being similar questions out there.
Basically, I have a class and I only need one instance of it, so I created a service for it:
services.factory('PlayerService', ->
new Player()
)
The class is related to a player and I'm trying to figure out how to update my view when the song changes.
Check out this simplified demo on Plunker that demonstrates the problem: http://plnkr.co/edit/L3WndT
Here's what I've attempted based on this question, but none of the solutions are working for me.
View
<div ng-controller="PlayerController">
{{ player.currentSong }}
</div>
First approach
PlayerController = ($scope, PlayerService) ->
$scope.player = PlayerService
return
Second approach
PlayerController = ($scope, PlayerService) ->
$scope.$watch(
'myApp.services.PlayerService'
(newval, oldval) ->
$scope.currentSong = newval
true
)
return