Angular 2.0.0-rc.2: How to migrate PLATFORM_DIRECT

2020-05-06 11:56发布

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.

标签: angular
1条回答
forever°为你锁心
2楼-- · 2020-05-06 12:50

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]}),
...]);
查看更多
登录 后发表回答