Child pages
  • Angular services

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

A service can get it scope from the $services angular service/factory that the system provides. On that factory you can ask for the service scope: 

$services.getServiceScope(serviceName);

...

This returns an angular $scope instance, that one holds an model property that is the javascript object that is synced between server and client (just as a webcomponent). Also that scope instance can be used to watch on its own properties, so that the service can interact with state changes from the server. This is for example very handy if the service must interact with a browser refresh, then the state is transferred over to the client and the service should use the model state of the scope to reconstruct it behavior. This is done in an angular run function that is executed when the browser page loads.

...