Angular2 RC6 Inject LOCALE_ID 捆绑后失败

Angular2 RC6 Inject LOCALE_ID fails after bundling

我正在尝试捆绑一个 Angular2 应用程序,刚刚更新到 RC6,松散地基于 this excellent blog post.

我有一个只包装内置 DatePipe 的管道,不同之处在于它接受空参数并在接收到该参数的情况下执行某些操作。对于 RC6,这必须更新以将 _locale 参数传递给 DatePipe。这是管道:

import {Pipe, PipeTransform, Inject, LOCALE_ID} from '@angular/core';
import {DatePipe} from '@angular/common';

@Pipe({
    name: 'myDate',
})
export class MyDatePipe implements PipeTransform {
    constructor(@Inject(LOCALE_ID) private _locale: string){}

    transform(value: any, pattern?: string): string {
        if (value === null) {
            return 'Not Available';
        }

        return new DatePipe(this._locale).transform(value, pattern);
    }
}

这种依赖注入方法与one used by the built-in DatePipe (best I can tell).

相同

当为开发编译并加载 systemjs 时,这工作正常。但是在与 rollup 捆绑后, _locale 传递给构造函数时是 null 。包中的实例化如下所示:

this._pipe_myDate_0 = new MyDatePipe(this.parentInjector.get(LOCALE_ID));
// this.parentInjector.get(LOCALE_ID) == null

如果有帮助,我可以提供汇总配置和 tsconfigs - 但现在会推迟,因为它会给问题增加很多内容。现在的捆绑过程是:

ngc(es2015) -> rollup(es2015) -> tsc(es5)

应用程序的其余部分运行良好!我现在已经通过直接将 'en-US' 传递给 DatePipe 解决了这个问题,但我很好奇为什么它不起作用,我想正确地做到这一点。

为每个语言环境编译:

ngc --locale=en-US