Custom Service is not initializing


#1

I have created an angular service called myCustomService and registered as shown in this post. I’m getting service without initializing so I’m not able to call any methods from myCustomService.
my custom service is like this

import { Injectable } from '@angular/core';
import { MatDialog } from '@angular/material';
import { OpenDialogComponent } from '../../components/open-dialog/open-dialog.component';

@Injectable({
  providedIn: 'root'
})
export class MyCustomService {
  constructor(private dialog: MatDialog) { }
   openDialog() {
    let dialogRef = this.dialog.open(OpenDialogComponent, {
      width: '250px'
    });
    dialogRef.afterClosed().subscribe((data: boolean) => {
      if (data) {
        console.log(data);
      }
    });
  }
}

and i have registered this service like this

 { [BPMN.InjectionNames.myCustomService]: ['value', BPMN.MyCustomService] },

and i have injected my custom service like this

export class RTCamundaPropertiesProvider extends PropertiesActivator {
    static $inject = ['eventBus', 'bpmnFactory', 'elementRegistry', 'elementTemplates', 'translate', 'MyCustomService'];
    private camundaPropertiesProvider = new CamundaPropertiesProvider(this.eventBus, this.bpmnFactory, this.elementRegistry, this.elementTemplates, this.translate);
    private rtEntryFactory = new RTEntryFactory(this.eventBus);
    constructor(private eventBus: any, private bpmnFactory: any, private elementRegistry: any, private elementTemplates: any, private translate: any, private myCustomService: MyCustomService) {
        super(eventBus);
        console.log(this.myCustomService);
    }
}

here is my sample Git Hub project.
Thank you in advance
Nagu


#2

What’s the context? How are you instantiating the modeler?


#3

hi @philippfromme
Thanks for the reply. I am instantiating modeler in playGround-component.ts like below

  loadModeler() {
    this.container = document.getElementById('js-drop-zone');

    this.modeler = new RtBpmnModeler({
      container: '#js-canvas',
      keyboard: { bindTo: document },
      propertiesPanel: { parent: '#js-properties-panel' },
      elementTemplates: BPMN.CustomElementTemplate,
      additionalModules: this.additionalModules(),
      moddleExtensions: this.moddleExtensions(),
    });

    this.modeler.on('elementTemplates.errors', function (event) {
      console.error('template load errors', event.errors);
    });
    this.modeler.get('elementTemplatesLoader').reload();
    this.importXML(this.xml);
    this.diagramXml = this.xml;
    this.modeler.on('commandStack.changed', this.export.bind(this));
  }


#4

Make sure to specify the __init__ property in your module to make sure it will be instantiated.


#5

Hi @philippfromme
i have made changes for initializing the service as you suggested

  { __init__: [BPMN.InjectionNames.myCustomService], MyCustomService: ['value', BPMN.MyCustomService] },

still It is not initializing and I’m getting the error. Is there anything wrong in initialization?
Capture


#6

This seems to be a problem with one of your custom provider’s methods. Have you tried to debug into the issue?


#7

It is not even hitting the custom provider’s method. If i create instance for that service in
rtCamundaPropertiesProvider.ts then the provider methods are available and working fine. But my problem is I don’t create instance my class using new keyword. sharing any example which is having custom service is very helpful.
Thank you
Nagu


#8

This example bundles custom modules. Have you had a look at it yet?


#9

Yeah I have seen that Example but I have problem with only Angular Services not with any other Services.


#10

I’m sorry, I can’t help you with AngularJS-related issues as I am not familiar with the framework.