Service Development

A Servoy service is a plain Angular service with the @Injectable() annotation

It should just be correctly configured in the manifest and also in the specfile.

The spec file should container stuff like:

"ng2Config": { 
       "packageName": "@servoy/webnotifications",
       "serviceName": "WebNotificationsService",
       "moduleName": "WebNotificationsModule",
       "entryPoint": "dist/servoy/webnotifications"
    },

the packageName should be the same as in the manifest:

NPM-PackageName: @servoy/webnotifications

and the serviceName should be the same as the name of the class:

@Injectable()
export class WebNotificationsService {
}

also the module name is needed so that your service can include everything it needs in its module:

@NgModule({
    declarations: [],
    providers: [WindowRefService, WebNotificationsService, ServoyToastrService, ToastrService],
    imports: [
        CommonModule,
        ServoyPublicModule,
        ToastrModule.forRoot()
    ],
    exports: []
})
export class WebNotificationsModule {}

The entry point is just for servoy to know where the distribution (build output of the angular compiler) is in the package.

After that the model properties are just public fiels of the service and api are just public functions.

If it is needed that you want todo something when a property is changed you can just get/set in typescript:

get onIdle(): CallableFunction {
  return this._onIdle;
}

set onIdle(callback: CallableFunction) {
  this._onIdle = callback;
  this.restoreOnIdleState();
}

this sample does call restoreOnIdleState() when the onIdle model property is set.

Last updated