Error calling AddinClientService

I have done numerous addins in the past but I have never had this error before.

I have an angular app with a parent component and router outlet to the child component. Irrespective of whether I put this code in the parent or child I get the same error message.

In ngOnInit I have added the very simple code as follows:

public ngOnInit() {

console.log("in ngoniinit");

console.log("in 2");

this._AddinClientService.args.subscribe((args: AddinClientInitArgs) => {

console.log("In login.component addiniclientservice.args.subscribe");

this.environmentId = args.envId;

sessionStorage.setItem("envId", args.envId ?? "")

args.ready({

showUI: true, title: environment.appDisplayName

});

});

My console shows the following:

In app.component ngoninit
in ngoniinit
in 2
ERROR TypeError: Cannot read properties of undefined (reading 'app')
at r.initializeTheme (main-QVCS4SD6.js:234:77006)
at Object.init (main-QVCS4SD6.js:234:75400)
at r.handleMessage (main-QVCS4SD6.js:1:29864)
at windowMessageHandler (main-QVCS4SD6.js:1:26021)
at f.invokeTask (polyfills-FFHMD2TL.js:1:7068)
at Object.onInvokeTask (chunk-NBNEUFUA.js:7:29616)
at f.invokeTask (polyfills-FFHMD2TL.js:1:6989)
at t.runTask (polyfills-FFHMD2TL.js:1:2375)
at E.invokeTask [as invoke] (polyfills-FFHMD2TL.js:1:8144)
at I (polyfills-FFHMD2TL.js:1:15196)

(The first console line comes from the parent ngOnInit method).

It never comes out of my _AddinClientService clause. Is there something that has not been initialised correctly? Do I need to set something else up?

Thanks in advance for any help

Comments

  • So I have traced the error back to line 303 of addin-client.service.ts:

    That is the only reference to “app” in that method. The reference is to the SkyAppConfig service that is injected in. The app is not defined.

    I am not sure if this is related or not but… when I inject my own SkyAppConfig into my application, it does not appear to be initialized either. Both runtime and skyux properties come out as undefined.

    Should it be like this or have I done something wrong?


  • So… I think that I fixed this.

    I am not sure why it should cause this issue because this seems like bad design to me but…

    In my code there were references to SkyAppConfig which was being injected in the root app.config.ts. (If you don't happen to have an app.config.ts file, it could be that you have put all your app configuration in your main.ts instead)

    When I removed this these errors went away and I was able to use the AddinClientService as intended without it crashing.

    Should it really be that fragile??

Categories