title: AngularJS: accessing scope in $resource factory definition
body: <p>I'm running an AngularJS app that incorporates Pusher for real-time updates of models. I'd like to trigger an action in a scope when pusher sends updated data for an AngularJS resource in the factory definition.</p>
  
  <p>I have a resource defined as follows:</p>
  
  <pre><code>TS.app.factory "Object", ($resource) -&gt;
    Object = $resource("objects/:publicToken", {publicToken: "@public_token"}, {update: {method: "PUT"}})
  
    # Checks for updates to object data via Pusher.
    Object::watch = -&gt;
      channelName = "private-12345"
  
      # See if we've already subscribed to this channel.
      channel = Namespace.pusher.channel(channelName)
  
      # If not, subscribe.
      channel ||= Namespace.pusher.subscribe(channelName)
  
      # Update data if we get new info from pusher.
      channel.bind "updated info", (data) =&gt;
        # THIS GETS RUN WHEN PUSHER SENDS UPDATED DATA.
        for key, value of data
          this[key] = value
        # TRIGGER ACTION HERE
  </code></pre>
  
  <p>I'd like to set variables in this resource's scope here. I know that for methods like $get, the scope will automatically update, but I don't know how to do that in this situation. How can I access the scope here?</p>
  
  <p>If there are other better (or more Angular-y) ways to do this, what are they?</p>