Page History
...
Code Block | ||
---|---|---|
| ||
{
"name": "testservice",
"displayName": "Test service that says helloworld",
"definition": "servoyservices/testservice/testservice.js",
"libraries": [],
"model":
{
"text": "string"
},
"api":
{
"talk": {
},
"helloworld":
{
"parameters":
[
{
"name":"text",
"type":"string"
}
]
}
}
}
|
The service js file must define the api from the spec:
Code Block | ||
---|---|---|
| ||
angular.module('testservice',['servoy'])
.factory("testservice",function($window,$services) {
var scope= $services.getServiceScope('testservice');
return {
talk: function() {
alert("talk: " + scope.model.text);
scope.model.text = "something else"
},
/**
* Say hello.
* @param {string} name your name
*/
helloworld: function(name) {
alert("Hello " + name);
}
}
})
.run(function($rootScope,$services)
{
var scope = $services.getServiceScope('testservice');
// watch the whole model (you can also use 'model.text' to only watch the text property)
scope.$watch('model', function(newvalue,oldvalue) {
// handle state changes
}, true);
}) |
...
Overview
Content Tools
Activity