Skip to content

Calling function 'InjectionToken', function calls are not supported. #16762

Closed
@fkolar

Description

@fkolar

I'm submitting a ... (check one with "x")

[X] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior
when I do ng build

I get:
Calling function 'InjectionToken', function calls are not supported. Consider replacing the function or lambda with a reference to an exported function, resolving symbol UserConfigToken in ....

I have created token and I am trying to use it as:

export const UserConfigToken = new InjectionToken<string>('User.Config');

export class CoreModule {
	 static forRoot(config: {[key: string]: any} = {}): ModuleWithProviders
    {
        return {
            ngModule: CoreModule,
            providers: [
                {provide: UserConfigToken, useValue: config},
}

Expected behavior

It will compile without these errors

I replaced OpaqueToken with InjectionToken and I think I am using it exactly the same one as in latest angular's 4.1.0 code e.g. when I look at
export const APP_BASE_HREF = new InjectionToken<string>('appBaseHref'); that I am using as well but I dont see any errors for this one.

I guess this usecase shoudl work...

What is the motivation / use case for changing the behavior?
OpaqueToken was deprecated

Please tell us about your environment:
I am running on latest Angular 4.1.0 as well as ng 1.0.3

Thanks for any input,

Frank

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions