Child pages
  • Angular services

Versions Compared

Key

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

...

The difference between service and web component is that service doesn't have user interface (so also doesn't have html template). A service must contain the specification file and the js file. The service specification file is exactly the same as web component specification file. However, as there is no UI, there is no support for handlers. Service API can be called from scripting as a plugin.

Code Block
titleservice specificationtestservice.spec
{
	"name": "testservice",
	"displayName": "Test service that says helloworld",
	"definition": "servoyservices/testservice/testservice.js",
	"libraries": [],
	"model":
	{
		"text": "string"
	},
	"api":
	{
	 	"talk": {
	        }
	}
}

The service js file must define the api from the spec:

Code Block
titletestservice.spec
angular.module('testservice',['servoy'])
.factory("testservice",function($window,$services) {
	var state = $services.getServiceState('testservice');
	return {
		talk: function() {
			alert("talk: " + state.text);
			state.text = "something else"
		}
	}
})