Angular using InjectionToken error

We need to enter a value using the InjectionToken , but we get the following error:

ERROR in An error was detected resolving character values ​​statically. Only marked variables and constants can be referenced, since the value of this variable is EDED by template by the compiler (position 3:12 in the source .ts file), allowing the $ symbol in C: / Projekte / Git / KWKPortal / App / src / app / shared /dnn.module.ts, Resolvin r AppModule character in C: /Projekte/Git/KWKPortal/App/src/app/app.module.ts, allowing AppModule character in C: / Projekte / Git / KWKPortal / app / SRC / application / applications. module.ts, Reso lving the AppModule symbol in C: /Projekte/Git/KWKPortal/App/src/app/app.module.ts

here is how we provide this value for input:

import { SF, $, dnn } from './shared/dnn.module';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule
  ],
  providers: [
    { provide: SF, useValue: $.ServicesFramework(dnn.getVars().ModuleId) }
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

dnn.module:

import { InjectionToken } from '@angular/core';

export let $: any;
export let dnn: any;
export let SF = new InjectionToken<any>('sf');

, ? useValue ?

0
1

, factory, :

export function servicesFrameworkFactory() {
  return $.ServicesFramework(dnn.getVars().ModuleId);
}

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule
  ],
  providers: [{
    provide: SF,
    useFactory: servicesFrameworkFactory,
    deps: []
  }],
  bootstrap: [AppComponent]
})
export class AppModule { }

, , .

0

Source: https://habr.com/ru/post/1667039/


All Articles