Angular 2.0.0-rc.2: How to migrate PLATFORM_DIRECT

2020-05-06 12:04发布

问题:

The changelog at https://github.com/angular/angular/blob/master/CHANGELOG.md mentions:

PLATFORM_PIPES and PLATFORM_DIRECTIVES now are fields on CompilerConfig. Instead of providing a binding to these tokens, provide a binding for CompilerConfig instead.

So far I have these lines in my bootstrap file:

bootstrap(
    AppComponent,
    [...
        provide(PLATFORM_DIRECTIVES, {useValue: ROUTER_DIRECTIVES, multi: true}),
    ...]);

How should I change the function provide()? Any hint is appreciated.

回答1:

I used the disableDeprecatedForms() method from here as a guide: https://github.com/angular/angular/blob/master/modules/@angular/forms/src/form_providers.ts

So your code should look something like:

    bootstrap(
AppComponent,
[...
    provide(CompilerConfig, {
        useFactory: (platformDirectives: any[], platformPipes: any[]) => {
            return new CompilerConfig({
                platformDirectives: platformDirectives.concat(...ROUTER_DIRECTIVES),
                platformPipes: platformPipes
            });
        },
        deps: [PLATFORM_DIRECTIVES, PLATFORM_PIPES]}),
...]);


标签: angular